Make WordPress Core

Ticket #36638: 36638.patch

File 36638.patch, 5.4 KB (added by rockwell15, 9 years ago)
  • src/wp-admin/admin-ajax.php

     
    6262        'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs',
    6363        'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail',
    6464        'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post',
    65         'press-this-add-category', 'crop-image', 'generate-password', 'save-wporg-username',
     65        'press-this-add-category', 'crop-image', 'generate-password', 'save-wporg-username', 'url-exists',
    6666);
    6767
    6868// Deprecated
  • src/wp-admin/includes/ajax-actions.php

     
    33273327
    33283328        wp_send_json_success( update_user_meta( get_current_user_id(), 'wporg_favorites', $username ) );
    33293329}
     3330
     3331/**
     3332 * Ajax handler for checking the existence of a URL.
     3333 *
     3334 * @since 4.6.0
     3335 */
     3336function wp_ajax_url_exists() {
     3337
     3338
     3339        $array = get_headers( $_POST['check_url'] );
     3340        $string = $array[0];
     3341
     3342        if( '' != $string && ! preg_match( '/4[0-9][0-9]/', $string ) ) {
     3343                wp_send_json_success('success');
     3344        } else {
     3345                wp_send_json_error('failed');
     3346        }
     3347
     3348}
  • src/wp-includes/css/editor.css

     
    17751775        margin: 2px 1px;
    17761776}
    17771777
     1778div.wp-link-bad {
     1779        display: none;
     1780    cursor: default;
     1781    margin: 5px;
     1782    float: right;
     1783    font-weight: 600;
     1784    color: #a00;
     1785}
     1786
    17781787.mce-inline-toolbar-grp .mce-btn-group .mce-btn:last-child {
    17791788        margin-right: 2px;
    17801789}
  • src/wp-includes/js/tinymce/plugins/wplink/plugin.js

     
    8484                }
    8585        } );
    8686
     87        tinymce.ui.WPBadLink = tinymce.ui.Control.extend( {
     88                renderHtml: function() {
     89                        return (
     90                                '<div id="' + this._id + '" class="wp-link-bad" title="This URL does not lead to a working page.">Bad Link</div>'
     91                        );
     92                },
     93        } );
     94
     95
    8796        tinymce.PluginManager.add( 'wplink', function( editor ) {
    8897                var toolbar;
    8998                var editToolbar;
     
    133142                function removePlaceholderStrings( content, dataAttr ) {
    134143                        if ( dataAttr ) {
    135144                                content = content.replace( / data-wplink-edit="true"/g, '' );
     145                                content = content.replace( / data-link-broken="true"/g, '' );
    136146                        }
    137147
    138148                        return content.replace( /<a [^>]*?href="_wp_link_placeholder"[^>]*>([\s\S]+)<\/a>/g, '$1' );
     
    143153                                toolbar = editor.wp._createToolbar( [
    144154                                        'wp_link_preview',
    145155                                        'wp_link_edit',
    146                                         'wp_link_remove'
     156                                        'wp_link_remove',
     157                                        'wp_link_bad',
    147158                                ], true );
    148159
    149160                                var editButtons = [
     
    226237                                        href = 'http://' + href;
    227238                                }
    228239
     240                                try {
     241                                        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     242                                } catch ( e1 ) {
     243                                        try {
     244                                                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     245                                        } catch ( e2 ) {
     246                                                xmlhttp = false;
     247                                        }
     248                                }
     249
     250                                if ( ! xmlhttp ) {
     251                                        if ( 'undefined' != typeof XMLHttpRequest ) {
     252                                                xmlhttp = new XMLHttpRequest();
     253                                        } else if ( window.createRequest ) {
     254                                                xmlhttp = window.createRequest();
     255                                        } else {
     256                                                xmlhttp = false;
     257                                        }
     258                                }
     259
     260                                if( false != xmlhttp ) {
     261                                        var data = {
     262                                                type: 'POST',
     263                                                check_url: href,
     264                                        }
     265
     266                                        wp.ajax.send( 'url-exists', {
     267                                                data: data,
     268                                                success: function () {
     269                                                        linkNode.removeAttribute( 'data-link-broken' );
     270                                                        badLinkFlag.css('display', 'none');
     271                                                },
     272                                                error: function() {
     273                                                        linkNode.setAttribute( 'data-link-broken', true );
     274                                                        badLinkFlag.css('display', 'block');
     275                                                },
     276                                        });
     277                                }
     278
    229279                                editor.dom.setAttribs( linkNode, { href: href, 'data-wplink-edit': null } );
    230280
    231281                                if ( ! tinymce.trim( linkNode.innerHTML ) ) {
     
    483533                        editToolbar.tempHide = false;
    484534
    485535                        if ( linkNode ) {
     536
     537                                if( linkNode.hasAttribute('data-link-broken') ) {
     538                                        badLinkFlag.css('display', 'block');
     539                                } else {
     540                                        badLinkFlag.css('display', 'none');
     541                                }
     542
    486543                                $linkNode = editor.$( linkNode );
    487544                                href = $linkNode.attr( 'href' );
    488545                                edit = $linkNode.attr( 'data-wplink-edit' );
     
    551608                        classes: 'widget btn primary'
    552609                } );
    553610
     611                editor.addButton( 'wp_link_bad', {
     612                        type: 'WPBadLink',
     613                        onPostRender: function() {
     614                                badLinkFlag = $('#'+this._id);
     615                        }
     616                } );
     617
    554618                return {
    555619                        close: function() {
    556620                                editToolbar.tempHide = false;
     
    558622                        }
    559623                };
    560624        } );
    561 } )( window.tinymce );
     625} )( window.tinymce );
     626 No newline at end of file
  • src/wp-includes/js/tinymce/skins/wordpress/wp-content.css

     
    501501        float: right;
    502502}
    503503
     504/* For bad links in the text editor */
     505a[data-link-broken="true"] {
     506        color: #a00;
     507}
     508
    504509@media print,
    505510        (-o-min-device-pixel-ratio: 5/4),
    506511        (-webkit-min-device-pixel-ratio: 1.25),