Make WordPress Core

Ticket #36638: 36638.8.patch

File 36638.8.patch, 6.2 KB (added by afercia, 9 years ago)
  • src/wp-admin/includes/ajax-actions.php

     
    39063906                $href = get_bloginfo( 'url' ) . $href;
    39073907        }
    39083908
    3909         $response = wp_safe_remote_get( $href, array(
     3909        $response = wp_remote_get( $href, array(
    39103910                'timeout' => 15,
    39113911                // Use an explicit user-agent
    39123912                'user-agent' => 'WordPress URL Test',
    39133913        ) );
    39143914
    3915         $message = null;
     3915        $error = false;
    39163916
    39173917        if ( is_wp_error( $response ) ) {
    3918                 $error = $response->get_error_message();
    3919 
    3920                 if ( strpos( $message, 'resolve host' ) !== false ) {
    3921                         $message = array( 'error' => __( 'Invalid host name.' ) );
     3918                if ( strpos( $response->get_error_message(), 'resolve host' ) !== false ) {
     3919                        $error = true;
    39223920                }
    3923 
    3924                 wp_send_json_error( $message );
     3921        } elseif ( wp_remote_retrieve_response_code( $response ) === 404 ) {
     3922                $error = true;
    39253923        }
    39263924
    3927         if ( wp_remote_retrieve_response_code( $response ) === 404 ) {
    3928                 wp_send_json_error( array( 'error' => __( 'Not found, HTTP error 404.' ) ) );
     3925        if ( $error ) {
     3926                wp_send_json_error( array( 'httpError' => true ) );
    39293927        }
    39303928
    39313929        wp_send_json_success();
  • src/wp-includes/class-wp-editor.php

     
    10651065                        'Ctrl + letter:' => __( 'Ctrl + letter:' ),
    10661066                        'Letter' => __( 'Letter' ),
    10671067                        'Action' => __( 'Action' ),
    1068                         'Invalid host name.' => __( 'Invalid host name.' ),
     1068                        'Warning: the link has been inserted but the link destination cannot be reached.' => __( 'Warning: the link has been inserted but the link destination cannot be reached.' ),
    10691069                        '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.' =>
    10701070                                __( '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.' ),
    10711071                        '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.' =>
  • src/wp-includes/js/tinymce/plugins/wplink/plugin.js

     
    9494                var doingUndoRedoTimer;
    9595                var $ = window.jQuery;
    9696                var urlErrors = {};
     97                var emailRegex = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i;
    9798
    9899                function getSelectedLink() {
    99100                        var href, html,
     
    147148                        });
    148149                }
    149150
     151                function setLinkError( $link ) {
     152                        var href = $link.attr( 'href' );
     153
     154                        $link.attr( 'data-wplink-url-error', 'true' );
     155
     156                        if ( window.wp && window.wp.a11y && window.wp.a11y.speak ) {
     157                                window.wp.a11y.speak( editor.translate( 'Warning: the link has been inserted but the link destination cannot be reached.' ), 'assertive' );
     158                        }
     159
     160                        if ( toolbar && toolbar.visible() ) {
     161                                toolbar.$el.find( '.wp-link-preview a' ).addClass( 'wplink-url-error' );
     162                        }
     163                }
     164
    150165                function checkLink( node ) {
    151166                        var $link = editor.$( node );
    152167                        var href = $link.attr( 'href' );
     
    155170                                return;
    156171                        }
    157172
    158                         // Early check
    159                         if ( /^http/i.test( href ) && ! /\.[a-z]{2,63}(\/|$)/i.test( href ) ) {
    160                                 urlErrors[href] = tinymce.translate( 'Invalid host name.' );
     173                        if ( /^http/i.test( href ) && ! /^https?:\/\/[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}(\/|$)/i.test( href ) ) {
     174                                urlErrors[href] = true;
    161175                        }
    162176
    163177                        if ( urlErrors.hasOwnProperty( href ) ) {
    164                                 $link.attr( 'data-wplink-url-error', 'true' );
     178                                setLinkError( $link );
    165179                                return;
    166180                        } else {
    167181                                $link.removeAttr( 'data-wplink-url-error' );
     
    179193                                        return;
    180194                                }
    181195
    182                                 if ( response.data && response.data.error ) {
    183                                         urlErrors[href] = response.data.error;
    184                                         $link.attr( 'data-wplink-url-error', 'true' );
    185 
    186                                         if ( toolbar && toolbar.visible() ) {
    187                                                 toolbar.$el.find( '.wp-link-preview a' ).addClass( 'wplink-url-error' ).attr( 'title', editor.dom.encode( response.data.error ) );
    188                                         }
     196                                if ( response.data && response.data.httpError ) {
     197                                        urlErrors[href] = true;
     198                                        setLinkError( $link );
    189199                                }
    190200                        });
    191201                }
     
    274284                                        return;
    275285                                }
    276286
    277                                 if ( ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( href ) ) {
     287                                if ( ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( href ) && ! emailRegex.test( href ) ) {
    278288                                        href = 'http://' + href;
    279289                                }
    280290
     
    536546
    537547                editor.on( 'wptoolbar', function( event ) {
    538548                        var linkNode = editor.dom.getParent( event.element, 'a' ),
    539                                 $linkNode, href, edit, title;
     549                                $linkNode, href, edit;
    540550
    541551                        if ( typeof window.wpLink !== 'undefined' && window.wpLink.modalOpen ) {
    542552                                editToolbar.tempHide = true;
     
    561571                                        previewInstance.setURL( href );
    562572                                        event.element = linkNode;
    563573                                        event.toolbar = toolbar;
    564                                         title = urlErrors.hasOwnProperty( href ) ? editor.dom.encode( urlErrors[ href ] ) : null;
    565574
    566575                                        if ( $linkNode.attr( 'data-wplink-url-error' ) === 'true' ) {
    567                                                 toolbar.$el.find( '.wp-link-preview a' ).addClass( 'wplink-url-error' ).attr( 'title', title );
     576                                                toolbar.$el.find( '.wp-link-preview a' ).addClass( 'wplink-url-error' );
    568577                                        } else {
    569                                                 toolbar.$el.find( '.wp-link-preview a' ).removeClass( 'wplink-url-error' ).attr( 'title', null );
     578                                                toolbar.$el.find( '.wp-link-preview a' ).removeClass( 'wplink-url-error' );
    570579                                        }
    571580                                }
    572581                        } else if ( editToolbar.visible() ) {
  • src/wp-includes/js/wplink.js

     
    22
    33( function( $, wpLinkL10n, wp ) {
    44        var editor, searchTimer, River, Query, correctedURL, linkNode,
    5                 emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
    6                 urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i,
     5                emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,63}$/i,
     6                urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,63}[^ "]*$/i,
    77                inputs = {},
    88                rivers = {},
    99                isTouch = ( 'ontouchend' in document );