TinyMCE, inline link:
- Remove proxying through WordPress to test if an URL exists. - Fix and enhance the regex that tests if the URL is well formed. Fixes #36638. Built from https://develop.svn.wordpress.org/trunk@38159 git-svn-id: http://core.svn.wordpress.org/trunk@38100 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
101545cbb5
commit
5bccb0020d
|
@ -64,7 +64,7 @@ $core_actions_post = array(
|
|||
'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post',
|
||||
'press-this-add-category', 'crop-image', 'generate-password', 'save-wporg-username', 'delete-plugin',
|
||||
'search-plugins', 'search-install-plugins', 'activate-plugin', 'update-theme', 'delete-theme',
|
||||
'install-theme', 'test_url', 'get-post-thumbnail-html',
|
||||
'install-theme', 'get-post-thumbnail-html',
|
||||
);
|
||||
|
||||
// Deprecated
|
||||
|
|
|
@ -3886,46 +3886,3 @@ function wp_ajax_search_install_plugins() {
|
|||
|
||||
wp_send_json_success( $status );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax handler for testing if a URL exists.
|
||||
*
|
||||
* Used in the editor.
|
||||
*
|
||||
* @since 4.6.0
|
||||
*/
|
||||
function wp_ajax_test_url() {
|
||||
if ( ! current_user_can( 'edit_posts' ) || ! wp_verify_nonce( $_POST['nonce'], 'wp-test-url' ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$href = esc_url_raw( $_POST['href'] );
|
||||
|
||||
// Relative URL
|
||||
if ( strpos( $href, '//' ) !== 0 && in_array( $href[0], array( '/', '#', '?' ), true ) ) {
|
||||
$href = get_bloginfo( 'url' ) . $href;
|
||||
}
|
||||
|
||||
// No redirects
|
||||
$response = wp_safe_remote_get( $href, array(
|
||||
'timeout' => 15,
|
||||
// Use an explicit user-agent
|
||||
'user-agent' => 'WordPress URL Test',
|
||||
) );
|
||||
|
||||
$error = false;
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
if ( strpos( $response->get_error_message(), 'resolve host' ) !== false ) {
|
||||
$error = true;
|
||||
}
|
||||
} elseif ( wp_remote_retrieve_response_code( $response ) === 404 ) {
|
||||
$error = true;
|
||||
}
|
||||
|
||||
if ( $error ) {
|
||||
wp_send_json_error( array( 'httpError' => true ) );
|
||||
}
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
|
|
@ -1065,7 +1065,7 @@ final class _WP_Editors {
|
|||
'Ctrl + letter:' => __( 'Ctrl + letter:' ),
|
||||
'Letter' => __( 'Letter' ),
|
||||
'Action' => __( 'Action' ),
|
||||
'Warning: the link has been inserted but the destination cannot be reached.' => __( 'Warning: the link has been inserted but the destination cannot be reached.' ),
|
||||
'Warning: the link has been inserted but may have errors. Please test it.' => __( 'Warning: the link has been inserted but may have errors. Please test it.' ),
|
||||
'To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.' =>
|
||||
__( 'To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.' ),
|
||||
'When starting a new paragraph with one of these formatting shortcuts followed by a space, the formatting will be applied automatically. Press Backspace or Escape to undo.' =>
|
||||
|
@ -1286,13 +1286,7 @@ final class _WP_Editors {
|
|||
</script>
|
||||
<?php
|
||||
|
||||
$has_wplink = in_array( 'wplink', self::$plugins, true );
|
||||
|
||||
if ( $has_wplink ) {
|
||||
echo '<input type="hidden" id="_wplink_urltest_nonce" value="' . wp_create_nonce( 'wp-test-url' ) . '" />';
|
||||
}
|
||||
|
||||
if ( $has_wplink || in_array( 'link', self::$qt_buttons, true ) ) {
|
||||
if ( in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) ) {
|
||||
self::wp_link_dialog();
|
||||
}
|
||||
|
||||
|
|
|
@ -93,8 +93,9 @@
|
|||
var doingUndoRedo;
|
||||
var doingUndoRedoTimer;
|
||||
var $ = window.jQuery;
|
||||
var urlErrors = {};
|
||||
var emailRegex = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i;
|
||||
var urlRegex1 = /^https?:\/\/([^\s/?.#-][^\s\/?.#]*\.?)+(\/[^\s"]*)?$/i;
|
||||
var urlRegex2 = /^https?:\/\/[^\/]+\.[^\/]+($|\/)/i;
|
||||
var speak = ( typeof window.wp !== 'undefined' && window.wp.a11y && window.wp.a11y.speak ) ? window.wp.a11y.speak : function() {};
|
||||
var hasLinkError = false;
|
||||
|
||||
|
@ -150,16 +151,6 @@
|
|||
});
|
||||
}
|
||||
|
||||
function setLinkError( $link ) {
|
||||
hasLinkError = true;
|
||||
$link.attr( 'data-wplink-url-error', 'true' );
|
||||
speak( editor.translate( 'Warning: the link has been inserted but the destination cannot be reached.' ), 'assertive' );
|
||||
|
||||
if ( toolbar && toolbar.visible() ) {
|
||||
toolbar.$el.find( '.wp-link-preview a' ).addClass( 'wplink-url-error' );
|
||||
}
|
||||
}
|
||||
|
||||
function checkLink( node ) {
|
||||
var $link = editor.$( node );
|
||||
var href = $link.attr( 'href' );
|
||||
|
@ -170,34 +161,13 @@
|
|||
|
||||
hasLinkError = false;
|
||||
|
||||
if ( /^http/i.test( href ) && ! /^https?:\/\/[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}(\/|$)/i.test( href ) ) {
|
||||
urlErrors[href] = true;
|
||||
}
|
||||
|
||||
if ( urlErrors.hasOwnProperty( href ) ) {
|
||||
setLinkError( $link );
|
||||
return;
|
||||
if ( /^http/i.test( href ) && ( ! urlRegex1.test( href ) || ! urlRegex2.test( href ) ) ) {
|
||||
hasLinkError = true;
|
||||
$link.attr( 'data-wplink-url-error', 'true' );
|
||||
speak( editor.translate( 'Warning: the link has been inserted but may have errors. Please test it.' ), 'assertive' );
|
||||
} else {
|
||||
$link.removeAttr( 'data-wplink-url-error' );
|
||||
}
|
||||
|
||||
$.post(
|
||||
window.ajaxurl, {
|
||||
action: 'test_url',
|
||||
nonce: $( '#_wplink_urltest_nonce' ).val(),
|
||||
href: href
|
||||
},
|
||||
'json'
|
||||
).done( function( response ) {
|
||||
if ( response.success ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( response.data && response.data.httpError ) {
|
||||
urlErrors[href] = true;
|
||||
setLinkError( $link );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
editor.on( 'preinit', function() {
|
||||
|
|
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.6-beta4-38158';
|
||||
$wp_version = '4.6-beta4-38159';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue