Make WordPress Core

Ticket #20210: 20210.5.diff

File 20210.5.diff, 13.4 KB (added by ryan, 13 years ago)
  • wp-includes/kses.php

     
    5151        $allowedposttags = array(
    5252                'address' => array(),
    5353                'a' => array(
    54                         'class' => true,
    5554                        'href' => true,
    56                         'id' => true,
    57                         'title' => true,
    5855                        'rel' => true,
    5956                        'rev' => true,
    6057                        'name' => true,
    6158                        'target' => true,
    6259                ),
    63                 'abbr' => array(
    64                         'class' => true,
    65                         'title' => true,
     60                'abbr' => array(),
     61                'acronym' => array(),
     62                'area' => array(
     63                        'alt' => true,
     64                        'coords' => true,
     65                        'href' => true,
     66                        'nohref' => true,
     67                        'shape' => true,
     68                        'target' => true,
    6669                ),
    67                 'acronym' => array(
    68                         'title' => true,
    69                 ),
    7070                'article' => array(
    7171                        'align' => true,
    72                         'class' => true,
    7372                        'dir' => true,
    7473                        'lang' => true,
    75                         'style' => true,
    7674                        'xml:lang' => true,
    7775                ),
    7876                'aside' => array(
    7977                        'align' => true,
    80                         'class' => true,
    8178                        'dir' => true,
    8279                        'lang' => true,
    83                         'style' => true,
    8480                        'xml:lang' => true,
    8581                ),
    8682                'b' => array(),
    8783                'big' => array(),
    8884                'blockquote' => array(
    89                         'id' => true,
    9085                        'cite' => true,
    91                         'class' => true,
    9286                        'lang' => true,
    9387                        'xml:lang' => true,
    9488                ),
    95                 'br' => array (
    96                         'class' => true,
    97                 ),
     89                'br' => array (),
    9890                'button' => array(
    9991                        'disabled' => true,
    10092                        'name' => true,
     
    10395                ),
    10496                'caption' => array(
    10597                        'align' => true,
    106                         'class' => true,
    10798                ),
    10899                'cite' => array (
    109                         'class' => true,
    110100                        'dir' => true,
    111101                        'lang' => true,
    112                         'title' => true,
    113102                ),
    114                 'code' => array (
    115                         'style' => true,
    116                 ),
     103                'code' => array (),
    117104                'col' => array(
    118105                        'align' => true,
    119106                        'char' => true,
    120107                        'charoff' => true,
    121108                        'span' => true,
    122109                        'dir' => true,
    123                         'style' => true,
    124110                        'valign' => true,
    125111                        'width' => true,
    126112                ),
     
    130116                'dd' => array(),
    131117                'details' => array(
    132118                        'align' => true,
    133                         'class' => true,
    134119                        'dir' => true,
    135120                        'lang' => true,
    136121                        'open' => true,
    137                         'style' => true,
    138122                        'xml:lang' => true,
    139123                ),
    140124                'div' => array(
    141125                        'align' => true,
    142                         'class' => true,
    143126                        'dir' => true,
    144127                        'lang' => true,
    145                         'style' => true,
    146128                        'xml:lang' => true,
    147129                ),
    148130                'dl' => array(),
     
    151133                'fieldset' => array(),
    152134                'figure' => array(
    153135                        'align' => true,
    154                         'class' => true,
    155136                        'dir' => true,
    156137                        'lang' => true,
    157                         'style' => true,
    158138                        'xml:lang' => true,
    159139                ),
    160140                'figcaption' => array(
    161141                        'align' => true,
    162                         'class' => true,
    163142                        'dir' => true,
    164143                        'lang' => true,
    165                         'style' => true,
    166144                        'xml:lang' => true,
    167145                ),
    168146                'font' => array(
     
    172150                ),
    173151                'footer' => array(
    174152                        'align' => true,
    175                         'class' => true,
    176153                        'dir' => true,
    177154                        'lang' => true,
    178                         'style' => true,
    179155                        'xml:lang' => true,
    180156                ),
    181157                'form' => array(
     
    189165                ),
    190166                'h1' => array(
    191167                        'align' => true,
    192                         'class' => true,
    193                         'id'    => true,
    194                         'style' => true,
    195168                ),
    196169                'h2' => array (
    197170                        'align' => true,
    198                         'class' => true,
    199                         'id'    => true,
    200                         'style' => true,
    201171                ),
    202172                'h3' => array (
    203173                        'align' => true,
    204                         'class' => true,
    205                         'id'    => true,
    206                         'style' => true,
    207174                ),
    208175                'h4' => array (
    209176                        'align' => true,
    210                         'class' => true,
    211                         'id'    => true,
    212                         'style' => true,
    213177                ),
    214178                'h5' => array (
    215179                        'align' => true,
    216                         'class' => true,
    217                         'id'    => true,
    218                         'style' => true,
    219180                ),
    220181                'h6' => array (
    221182                        'align' => true,
    222                         'class' => true,
    223                         'id'    => true,
    224                         'style' => true,
    225183                ),
    226184                'header' => array(
    227185                        'align' => true,
    228                         'class' => true,
    229186                        'dir' => true,
    230187                        'lang' => true,
    231                         'style' => true,
    232188                        'xml:lang' => true,
    233189                ),
    234190                'hgroup' => array(
    235191                        'align' => true,
    236                         'class' => true,
    237192                        'dir' => true,
    238193                        'lang' => true,
    239                         'style' => true,
    240194                        'xml:lang' => true,
    241195                ),
    242196                'hr' => array (
    243197                        'align' => true,
    244                         'class' => true,
    245198                        'noshade' => true,
    246199                        'size' => true,
    247200                        'width' => true,
    248201                ),
    249                 'i' => array(),
     202                'i' => array (),
    250203                'img' => array(
    251204                        'alt' => true,
    252205                        'align' => true,
    253206                        'border' => true,
    254                         'class' => true,
    255207                        'height' => true,
    256208                        'hspace' => true,
    257209                        'longdesc' => true,
    258210                        'vspace' => true,
    259211                        'src' => true,
    260                         'style' => true,
     212                        'usemap' => true,
    261213                        'width' => true,
    262214                ),
    263215                'ins' => array(
    264216                        'datetime' => true,
    265217                        'cite' => true,
    266218                ),
    267                 'kbd' => array(),
     219                'kbd' => array (),
    268220                'label' => array(
    269221                        'for' => true,
    270222                ),
     
    273225                ),
    274226                'li' => array (
    275227                        'align' => true,
    276                         'class' => true,
    277228                ),
     229                'map' => array(
     230                        'name' => true,
     231                ),
    278232                'menu' => array (
    279                         'class' => true,
    280                         'style' => true,
    281233                        'type' => true,
    282234                ),
    283235                'nav' => array(
    284236                        'align' => true,
    285                         'class' => true,
    286237                        'dir' => true,
    287238                        'lang' => true,
    288                         'style' => true,
    289239                        'xml:lang' => true,
    290240                ),
    291241                'p' => array(
    292                         'class' => true,
    293242                        'align' => true,
    294243                        'dir' => true,
    295244                        'lang' => true,
    296                         'style' => true,
    297245                        'xml:lang' => true,
    298246                ),
    299247                'pre' => array(
    300                         'style' => true,
    301248                        'width' => true,
    302249                ),
    303250                'q' => array(
     
    305252                ),
    306253                's' => array(),
    307254                'span' => array (
    308                         'class' => true,
    309255                        'dir' => true,
    310256                        'align' => true,
    311257                        'lang' => true,
    312                         'style' => true,
    313                         'title' => true,
    314258                        'xml:lang' => true,
    315259                ),
    316260                'section' => array(
    317261                        'align' => true,
    318                         'class' => true,
    319262                        'dir' => true,
    320263                        'lang' => true,
    321                         'style' => true,
    322264                        'xml:lang' => true,
    323265                ),
    324                 'small' => array(),
    325                 'strike' => array(),
    326                 'strong' => array(),
    327                 'sub' => array(),
     266                'small' => array (),
     267                'strike' => array (),
     268                'strong' => array (),
     269                'sub' => array (),
    328270                'summary' => array(
    329271                        'align' => true,
    330                         'class' => true,
    331272                        'dir' => true,
    332273                        'lang' => true,
    333                         'style' => true,
    334274                        'xml:lang' => true,
    335275                ),
    336                 'sup' => array(),
     276                'sup' => array (),
    337277                'table' => array(
    338278                        'align' => true,
    339279                        'bgcolor' => true,
    340280                        'border' => true,
    341281                        'cellpadding' => true,
    342282                        'cellspacing' => true,
    343                         'class' => true,
    344283                        'dir' => true,
    345                         'id' => true,
    346284                        'rules' => true,
    347                         'style' => true,
    348285                        'summary' => true,
    349286                        'width' => true,
    350287                ),
     
    361298                        'bgcolor' => true,
    362299                        'char' => true,
    363300                        'charoff' => true,
    364                         'class' => true,
    365301                        'colspan' => true,
    366302                        'dir' => true,
    367303                        'headers' => true,
     
    369305                        'nowrap' => true,
    370306                        'rowspan' => true,
    371307                        'scope' => true,
    372                         'style' => true,
    373308                        'valign' => true,
    374309                        'width' => true,
    375310                ),
     
    383318                'tfoot' => array(
    384319                        'align' => true,
    385320                        'char' => true,
    386                         'class' => true,
    387321                        'charoff' => true,
    388322                        'valign' => true,
    389323                ),
     
    394328                        'bgcolor' => true,
    395329                        'char' => true,
    396330                        'charoff' => true,
    397                         'class' => true,
    398331                        'colspan' => true,
    399332                        'headers' => true,
    400333                        'height' => true,
     
    408341                        'align' => true,
    409342                        'char' => true,
    410343                        'charoff' => true,
    411                         'class' => true,
    412344                        'valign' => true,
    413345                ),
    414346                'title' => array(),
     
    417349                        'bgcolor' => true,
    418350                        'char' => true,
    419351                        'charoff' => true,
    420                         'class' => true,
    421                         'style' => true,
    422352                        'valign' => true,
    423353                ),
    424                 'tt' => array(),
    425                 'u' => array(),
     354                'tt' => array (),
     355                'u' => array (),
    426356                'ul' => array (
    427                         'class' => true,
    428                         'style' => true,
    429357                        'type' => true,
    430358                ),
    431359                'ol' => array (
    432                         'class' => true,
    433360                        'start' => true,
    434                         'style' => true,
    435361                        'type' => true,
    436362                ),
    437363                'var' => array(),
     
    526452                'sdot',    'lceil',  'rceil',   'lfloor', 'rfloor', 'lang',
    527453                'rang',    'loz',    'spades',  'clubs',  'hearts', 'diams',
    528454        );
     455
     456        $allowedposttags = array_map( '_wp_add_global_attributes', $allowedposttags );
     457} else {
     458        $allowedtags = wp_kses_array_lc( $allowedtags );
     459        $allowedposttags = wp_kses_array_lc( $allowedposttags );
    529460}
    530461
    531462/**
     
    554485        $string = wp_kses_no_null($string);
    555486        $string = wp_kses_js_entities($string);
    556487        $string = wp_kses_normalize_entities($string);
    557         $allowed_html_fixed = wp_kses_array_lc($allowed_html);
    558         $string = wp_kses_hook($string, $allowed_html_fixed, $allowed_protocols); // WP changed the order of these funcs and added args to wp_kses_hook
    559         return wp_kses_split($string, $allowed_html_fixed, $allowed_protocols);
     488        $string = wp_kses_hook($string, $allowed_html, $allowed_protocols); // WP changed the order of these funcs and added args to wp_kses_hook
     489        return wp_kses_split($string, $allowed_html, $allowed_protocols);
    560490}
    561491
    562492/**
     493 * Return a list of allowed tags and attributes for a given context.
     494 *
     495 * @since 3.5.0
     496 *
     497 * @param string $context The context for which to retrieve tags. Allowed values are
     498 *  post | strip | data | entities or the name of a field filter such as pre_user_description.
     499 * @return array List of allowed tags and their allowed attributes.
     500 */
     501function wp_kses_allowed_html( $context = '' ) {
     502        global $allowedposttags, $allowedtags, $allowedentitynames;
     503
     504        if ( is_array( $context ) )
     505                return apply_filters( 'wp_kses_allowed_html', $context, 'explicit' );
     506
     507        switch ( $context ) {
     508                case 'post':
     509                        return apply_filters( 'wp_kses_allowed_html', $allowedposttags, $context );
     510                        break;
     511                case 'user_description':
     512                case 'pre_user_description':
     513                        $tags = $allowedtags;
     514                        $tags['a']['rel'] = true;
     515                        return apply_filters( 'wp_kses_allowed_html', $tags, $context );
     516                        break;
     517                case 'strip':
     518                        return apply_filters( 'wp_kses_allowed_html', array(), $context );
     519                        break;
     520                case 'entities':
     521                        return apply_filters( 'wp_kses_allowed_html', $allowedentitynames, $context);
     522                        break;
     523                case 'data':
     524                default:
     525                        return apply_filters( 'wp_kses_allowed_html', $allowedtags, $context );
     526        }
     527}
     528
     529/**
    563530 * You add any kses hooks here.
    564531 *
    565532 * There is currently only one kses WordPress hook and it is called here. All
     
    572539 * @param array $allowed_protocols Allowed protocol in links
    573540 * @return string Filtered content through 'pre_kses' hook
    574541 */
    575 function wp_kses_hook($string, $allowed_html, $allowed_protocols) {
     542function wp_kses_hook( $string, $allowed_html, $allowed_protocols ) {
    576543        $string = apply_filters('pre_kses', $string, $allowed_html, $allowed_protocols);
    577544        return $string;
    578545}
     
    600567 * @param array $allowed_protocols Allowed protocols to keep
    601568 * @return string Content with fixed HTML tags
    602569 */
    603 function wp_kses_split($string, $allowed_html, $allowed_protocols) {
     570function wp_kses_split( $string, $allowed_html, $allowed_protocols ) {
    604571        global $pass_allowed_html, $pass_allowed_protocols;
    605572        $pass_allowed_html = $allowed_html;
    606573        $pass_allowed_protocols = $allowed_protocols;
     
    668635        $elem = $matches[2];
    669636        $attrlist = $matches[3];
    670637
     638        if ( ! is_array( $allowed_html ) )
     639                $allowed_html = wp_kses_allowed_html( $allowed_html );
     640
    671641        if ( ! isset($allowed_html[strtolower($elem)]) )
    672642                return '';
    673643        # They are using a not allowed HTML element
     
    699669function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols) {
    700670        # Is there a closing XHTML slash at the end of the attributes?
    701671
     672        if ( ! is_array( $allowed_html ) )
     673                $allowed_html = wp_kses_allowed_html( $allowed_html );
     674
    702675        $xhtml_slash = '';
    703676        if (preg_match('%\s*/\s*$%', $attr))
    704677                $xhtml_slash = ' /';
     
    12861259 * @param string $data Content to filter, expected to be escaped with slashes
    12871260 * @return string Filtered content
    12881261 */
    1289 function wp_filter_kses($data) {
    1290         global $allowedtags;
    1291         return addslashes( wp_kses(stripslashes( $data ), $allowedtags) );
     1262function wp_filter_kses( $data ) {
     1263        return addslashes( wp_kses( stripslashes( $data ), current_filter() ) );
    12921264}
    12931265
    12941266/**
     
    13001272 * @param string $data Content to filter, expected to not be escaped
    13011273 * @return string Filtered content
    13021274 */
    1303 function wp_kses_data($data) {
    1304         global $allowedtags;
    1305         return wp_kses( $data , $allowedtags );
     1275function wp_kses_data( $data ) {
     1276        return wp_kses( $data , current_filter() );
    13061277}
    13071278
    13081279/**
     
    13121283 * data from forms.
    13131284 *
    13141285 * @since 2.0.0
    1315  * @uses $allowedposttags
    13161286 *
    13171287 * @param string $data Post content to filter, expected to be escaped with slashes
    13181288 * @return string Filtered post content with allowed HTML tags and attributes intact.
    13191289 */
    13201290function wp_filter_post_kses($data) {
    1321         global $allowedposttags;
    1322         return addslashes ( wp_kses(stripslashes( $data ), $allowedposttags) );
     1291        return addslashes ( wp_kses( stripslashes( $data ), 'post' ) );
    13231292}
    13241293
    13251294/**
     
    13291298 * data from forms.
    13301299 *
    13311300 * @since 2.9.0
    1332  * @uses $allowedposttags
    13331301 *
    13341302 * @param string $data Post content to filter
    13351303 * @return string Filtered post content with allowed HTML tags and attributes intact.
    13361304 */
    13371305function wp_kses_post($data) {
    1338         global $allowedposttags;
    1339         return wp_kses( $data , $allowedposttags );
     1306        return wp_kses( $data , 'post' );
    13401307}
    13411308
    13421309/**
     
    13471314 * @param string $data Content to strip all HTML from
    13481315 * @return string Filtered content without any HTML
    13491316 */
    1350 function wp_filter_nohtml_kses($data) {
    1351         return addslashes ( wp_kses(stripslashes( $data ), array()) );
     1317function wp_filter_nohtml_kses( $data ) {
     1318        return addslashes ( wp_kses( stripslashes( $data ), 'strip' ) );
    13521319}
    13531320
    13541321/**
     
    14841451
    14851452        return $css;
    14861453}
     1454
     1455/**
     1456 * Helper function to add global attributes to a tag in the allowed html list.
     1457 *
     1458 * @since 3.5.0
     1459 * @access private
     1460 *
     1461 * @param array $value An array of attributes.
     1462 * @return array The array of attributes with global attributes added.
     1463 */
     1464function _wp_add_global_attributes( $value ) {
     1465        $global_attributes = array(
     1466                'class' => true,
     1467                'id' => true,
     1468                'style' => true,
     1469                'title' => true,
     1470        );
     1471
     1472        if ( true === $value )
     1473                $value = array();
     1474
     1475        if ( is_array( $value ) )
     1476                return array_merge( $value, $global_attributes );
     1477
     1478        return $value;
     1479}