WordPress.org

Make WordPress Core

Changeset 23120


Ignore:
Timestamp:
12/07/2012 11:26:25 AM (8 years ago)
Author:
nacin
Message:

Add a sane, inclusive HTML element/attribute schema to TinyMCE.

TinyMCE 3.4.x (shipped with WordPress 3.4.x) had an HTML4-based schema definition, with HTML5 elements added to it. TinyMCE 3.5.x (shipping, again coincidentally, with WordPress 3.5) allows for HTML5 schema support, which also provides for full HTML5 attribute support. The problem is its HTML5 schema excludes all HTML4 elements and attributes that were dropped in the HTML5 spec, which is unacceptable behavior.

This "duck punch" of TinyMCE's Schema.js file creates a new, sane schema. It is TinyMCE's HTML4 and HTML5 schema definitions recursively merged.

Objects are not whitelisted in either schema to allow for embed elements as child nodes, so object, param, and embed remain separately whitelisted in the WordPress TinyMCE plugin. Our attempts to add other attributes in said plugin is now superceded.

props koopersmith, azaozz.
fixes #22790.

Location:
trunk/wp-includes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-editor.php

    r23017 r23120  
    570570
    571571        if ( $tmce_on ) {
    572             if ( $compressed )
     572            if ( $compressed ) {
    573573                echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&amp;$version'></script>\n";
    574             else
     574            } else {
    575575                echo "<script type='text/javascript' src='{$baseurl}/tiny_mce.js?$version'></script>\n";
     576                echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce-schema.js?$version'></script>\n";
     577            }
    576578
    577579            if ( 'en' != self::$mce_locale && isset($lang) )
  • trunk/wp-includes/js/tinymce/plugins/wordpress/editor_plugin_src.js

    r23112 r23120  
    136136            });
    137137
    138             // Add obsolete HTML attributes that are still in use.
     138            // Extend <object> and <embed> (#WP22790)
    139139            ed.onPreInit.add(function(ed) {
    140                 // The commonAttr are from TinyMCE 3.5.7 getHTML5()
    141                 // Obsolete attributes are from TinyMCE 3.5.7 getHTML4()
    142                 var commonAttr = 'id|accesskey|class|dir|draggable|item|hidden|itemprop|role|spellcheck|style|subject|title|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
    143                     tdAttr = commonAttr + '|abbr|axis|headers|scope|rowspan|colspan|char|charoff|align|valign|halign|nowrap|bgcolor|width|height';
    144                 // Obsolete table attributes
    145                 ed.schema.addValidElements('table['+commonAttr+'|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor]');
    146                 // Obsolete tr attributes
    147                 ed.schema.addValidElements('tr['+commonAttr+'|align|char|charoff|valign|halign|bgcolor]');
    148                 // Obsolete td and th attributes
    149                 ed.schema.addValidElements('td['+tdAttr+'],th['+tdAttr+']');
    150                 // Adds "name" for <a>
    151                 ed.schema.addValidElements('a['+commonAttr+'|href|target|ping|rel|media|type|name]');
    152                 // Extend <object> and <embed>
    153140                ed.schema.addValidElements('object[*],param[id|name|value|valuetype|type],embed[*]');
    154141                ed.schema.addValidChildren('object[*]');
  • trunk/wp-includes/js/tinymce/wp-tinymce-schema.js

    r23119 r23120  
    11/**
    2  * Schema.js
     2 * TinyMCE Schema.js
     3 *
     4 * Duck-punched by WordPress core to support a sane schema superset.
    35 *
    46 * Copyright, Moxiecode Systems AB
     
    321323
    322324    /**
     325     * WordPress Core
     326     *
     327     * Returns a schema that is the result of a deep merge between the HTML5
     328     * and HTML4 schemas.
     329     */
     330    function getSaneSchema() {
     331        var cachedMapCache = mapCache,
     332            html5, html4;
     333
     334        if ( mapCache.sane )
     335            return mapCache.sane;
     336
     337        // Bust the mapCache so we're not dealing with the other schema objects.
     338        mapCache = {};
     339        html5 = getHTML5();
     340        html4 = getHTML4();
     341        mapCache = cachedMapCache;
     342
     343        each( html4, function( html4settings, tag ) {
     344            var html5settings = html5[ tag ],
     345                difference = [];
     346
     347            // Merge tags missing in HTML5 mode.
     348            if ( ! html5settings ) {
     349                html5[ tag ] = html4settings;
     350                return;
     351            }
     352
     353            // Merge attributes missing from this HTML5 tag.
     354            each( html4settings.attributes, function( attribute, key ) {
     355                if ( ! html5settings.attributes[ key ] )
     356                    html5settings.attributes[ key ] = attribute;
     357            });
     358
     359            // Merge any missing attributes into the attributes order.
     360            each( html4settings.attributesOrder, function( key ) {
     361                if ( -1 === tinymce.inArray( html5settings.attributesOrder, key ) )
     362                    difference.push( key );
     363            });
     364
     365            html5settings.attributesOrder = html5settings.attributesOrder.concat( difference );
     366
     367            // Merge children missing from this HTML5 tag.
     368            each( html4settings.children, function( child, key ) {
     369                if ( ! html5settings.children[ key ] )
     370                    html5settings.children[ key ] = child;
     371            });
     372        });
     373
     374        return mapCache.sane = html5;
     375    }
     376
     377    /**
    323378     * Schema validator class.
    324379     *
     
    369424
    370425        settings = settings || {};
    371         schemaItems = settings.schema == "html5" ? getHTML5() : getHTML4();
     426
     427        /**
     428         * WordPress core uses a sane schema in place of the default "HTML5" schema.
     429         */
     430        schemaItems = settings.schema == "html5" ? getSaneSchema() : getHTML4();
    372431
    373432        // Allow all elements and attributes if verify_html is set to false
  • trunk/wp-includes/js/tinymce/wp-tinymce.php

    r22531 r23120  
    3434} else {
    3535    echo get_file($basepath . '/tiny_mce.js');
     36    echo get_file($basepath . '/wp-tinymce-schema.js');
    3637}
    3738exit;
Note: See TracChangeset for help on using the changeset viewer.