Ticket #36638: 36638.2.patch
File 36638.2.patch, 8.1 KB (added by , 9 years ago) |
---|
-
src/wp-admin/admin-ajax.php
64 64 'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post', 65 65 'press-this-add-category', 'crop-image', 'generate-password', 'save-wporg-username', 'delete-plugin', 66 66 'search-plugins', 'search-install-plugins', 'activate-plugin', 'update-theme', 'delete-theme', 67 'install-theme', 67 'install-theme', 'test_url', 68 68 ); 69 69 70 70 // Deprecated -
src/wp-admin/includes/ajax-actions.php
3832 3832 3833 3833 wp_send_json_success( $status ); 3834 3834 } 3835 3836 /** 3837 * Ajax handler for testing if an URL exists. Used in the editor. 3838 * 3839 * @since 4.6.0 3840 */ 3841 function wp_ajax_test_url() { 3842 if ( ! current_user_can( 'edit_posts' ) || ! wp_verify_nonce( $_POST['nonce'], 'wp-test-url' ) ) { 3843 wp_send_json_error(); 3844 } 3845 3846 $href = esc_url_raw( $_POST['href'] ); 3847 3848 // Relative URL 3849 if ( strpos( $href, '//' ) !== 0 && in_array( $href[0], array( '/', '#', '?' ), true ) ) { 3850 $href = get_bloginfo( 'url' ) . $href; 3851 } 3852 3853 $response = wp_safe_remote_get( $href, array( 3854 'timeout' => 15, 3855 // Use an explicit user-agent 3856 'user-agent' => 'WordPress URL Test', 3857 ) ); 3858 3859 $message = null; 3860 3861 if ( is_wp_error( $response ) ) { 3862 $error = $response->get_error_message(); 3863 3864 if ( strpos( $message, 'resolve host' ) !== false ) { 3865 $message = array( 'error' => __( 'Invalid host name.' ) ); 3866 } 3867 3868 wp_send_json_error( $message ); 3869 } 3870 3871 if ( wp_remote_retrieve_response_code( $response ) === 404 ) { 3872 wp_send_json_error( array( 'error' => __( 'Not found, HTTP error 404.' ) ) ); 3873 } 3874 3875 wp_send_json_success(); 3876 } -
src/wp-includes/class-wp-editor.php
1063 1063 'Ctrl + letter:' => __( 'Ctrl + letter:' ), 1064 1064 'Letter' => __( 'Letter' ), 1065 1065 'Action' => __( 'Action' ), 1066 'Invalid host name.' => __( 'Invalid host name.' ), 1066 1067 '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.' => 1067 1068 __( '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.' ), 1068 1069 '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.' => … … 1283 1284 </script> 1284 1285 <?php 1285 1286 1286 if ( in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) ) 1287 $has_wplink = in_array( 'wplink', self::$plugins, true ); 1288 1289 if ( $has_wplink ) { 1290 echo '<input type="hidden" id="_wplink_urltest_nonce" value="' . wp_create_nonce( 'wp-test-url' ) . '" />'; 1291 } 1292 1293 if ( $has_wplink || in_array( 'link', self::$qt_buttons, true ) ) { 1287 1294 self::wp_link_dialog(); 1295 } 1288 1296 1289 1297 /** 1290 1298 * Fires after any core TinyMCE editor instances are created. -
src/wp-includes/css/editor.css
1757 1757 cursor: pointer; 1758 1758 } 1759 1759 1760 div.wp-link-preview a.wplink-url-error { 1761 color: #a00; 1762 } 1763 1764 div.wp-link-preview a.wplink-url-error:hover { 1765 color: #f00; 1766 } 1767 1760 1768 div.wp-link-input { 1761 1769 float: left; 1762 1770 margin: 2px; -
src/wp-includes/js/tinymce/plugins/wplink/plugin.js
93 93 var doingUndoRedo; 94 94 var doingUndoRedoTimer; 95 95 var $ = window.jQuery; 96 var urlErrors = {}; 96 97 97 98 function getSelectedLink() { 98 99 var href, html, … … 131 132 } 132 133 133 134 function removePlaceholderStrings( content, dataAttr ) { 134 if ( dataAttr ) { 135 content = content.replace( / data-wplink-edit="true"/g, '' ); 135 return content.replace( /(<a [^>]+>)([\s\S]*?)<\/a>/g, function( all, tag, text ) { 136 if ( tag.indexOf( ' href="_wp_link_placeholder"' ) > -1 ) { 137 return text; 138 } 139 140 if ( dataAttr ) { 141 tag = tag.replace( / data-wplink-edit="true"/g, '' ); 142 } 143 144 tag = tag.replace( / data-wplink-url-error="true"/g, '' ); 145 146 return tag + text + '</a>'; 147 }); 148 } 149 150 function checkLink( node ) { 151 var $link = editor.$( node ); 152 var href = $link.attr( 'href' ); 153 154 if ( ! href || typeof $ === 'undefined' ) { 155 return; 136 156 } 137 157 138 return content.replace( /<a [^>]*?href="_wp_link_placeholder"[^>]*>([\s\S]+)<\/a>/g, '$1' ); 158 // Early check 159 if ( /^http/i.test( href ) && ! /\.[a-z]{2,63}(\/|$)/i.test( href ) ) { 160 urlErrors[href] = tinymce.translate( 'Invalid host name.' ); 161 } 162 163 if ( urlErrors.hasOwnProperty( href ) ) { 164 $link.attr( 'data-wplink-url-error', 'true' ); 165 return; 166 } else { 167 $link.removeAttr( 'data-wplink-url-error' ); 168 } 169 170 $.post( 171 window.ajaxurl, { 172 action: 'test_url', 173 nonce: $( '#_wplink_urltest_nonce' ).val(), 174 href: href 175 }, 176 'json' 177 ).done( function( response ) { 178 if ( response.success ) { 179 return; 180 } 181 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 } 189 } 190 }); 139 191 } 140 192 141 193 editor.on( 'preinit', function() { … … 231 283 if ( ! tinymce.trim( linkNode.innerHTML ) ) { 232 284 editor.$( linkNode ).text( text || href ); 233 285 } 286 287 checkLink( linkNode ); 234 288 } 235 289 236 290 inputInstance.reset(); … … 473 527 474 528 editor.on( 'wptoolbar', function( event ) { 475 529 var linkNode = editor.dom.getParent( event.element, 'a' ), 476 $linkNode, href, edit ;530 $linkNode, href, edit, title; 477 531 478 532 if ( typeof window.wpLink !== 'undefined' && window.wpLink.modalOpen ) { 479 533 editToolbar.tempHide = true; … … 498 552 previewInstance.setURL( href ); 499 553 event.element = linkNode; 500 554 event.toolbar = toolbar; 555 title = urlErrors.hasOwnProperty( href ) ? editor.dom.encode( urlErrors[ href ] ) : null; 556 557 if ( $linkNode.attr( 'data-wplink-url-error' ) === 'true' ) { 558 toolbar.$el.find( '.wp-link-preview a' ).addClass( 'wplink-url-error' ).attr( 'title', title ); 559 } else { 560 toolbar.$el.find( '.wp-link-preview a' ).removeClass( 'wplink-url-error' ).attr( 'title', null ); 561 } 501 562 } 502 563 } 503 564 } ); … … 555 616 close: function() { 556 617 editToolbar.tempHide = false; 557 618 editor.execCommand( 'wp_link_cancel' ); 558 } 619 }, 620 checkLink: checkLink 559 621 }; 560 622 } ); 561 623 } )( window.tinymce ); -
src/wp-includes/js/tinymce/skins/wordpress/wp-content.css
205 205 visibility: hidden; 206 206 } 207 207 208 a[data-wplink-url-error] { 209 color: #fff; 210 outline: 4px solid #b00; 211 background: #b00; 212 } 213 208 214 /** 209 215 * WP Views 210 216 */ -
src/wp-includes/js/wplink.js
434 434 editor.focus(); 435 435 editor.nodeChanged(); 436 436 437 if ( link && editor.plugins.wplink ) { 438 editor.plugins.wplink.checkLink( link ); 439 } 440 437 441 // Audible confirmation message when a link has been inserted in the Editor. 438 442 wp.a11y.speak( wpLinkL10n.linkInserted ); 439 443 },