Make WordPress Core

Ticket #20210: 20210.3.diff

File 20210.3.diff, 12.9 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,
    112102                        'title' => true,
    113103                ),
    114                 'code' => array (
    115                         'style' => true,
    116                 ),
     104                'code' => array (),
    117105                'col' => array(
    118106                        'align' => true,
    119107                        'char' => true,
    120108                        'charoff' => true,
    121109                        'span' => true,
    122110                        'dir' => true,
    123                         'style' => true,
    124111                        'valign' => true,
    125112                        'width' => true,
    126113                ),
     
    130117                'dd' => array(),
    131118                'details' => array(
    132119                        'align' => true,
    133                         'class' => true,
    134120                        'dir' => true,
    135121                        'lang' => true,
    136122                        'open' => true,
    137                         'style' => true,
    138123                        'xml:lang' => true,
    139124                ),
    140125                'div' => array(
    141126                        'align' => true,
    142                         'class' => true,
    143127                        'dir' => true,
    144128                        'lang' => true,
    145                         'style' => true,
    146129                        'xml:lang' => true,
    147130                ),
    148131                'dl' => array(),
     
    151134                'fieldset' => array(),
    152135                'figure' => array(
    153136                        'align' => true,
    154                         'class' => true,
    155137                        'dir' => true,
    156138                        'lang' => true,
    157                         'style' => true,
    158139                        'xml:lang' => true,
    159140                ),
    160141                'figcaption' => array(
    161142                        'align' => true,
    162                         'class' => true,
    163143                        'dir' => true,
    164144                        'lang' => true,
    165                         'style' => true,
    166145                        'xml:lang' => true,
    167146                ),
    168147                'font' => array(
     
    172151                ),
    173152                'footer' => array(
    174153                        'align' => true,
    175                         'class' => true,
    176154                        'dir' => true,
    177155                        'lang' => true,
    178                         'style' => true,
    179156                        'xml:lang' => true,
    180157                ),
    181158                'form' => array(
     
    189166                ),
    190167                'h1' => array(
    191168                        'align' => true,
    192                         'class' => true,
    193                         'id'    => true,
    194                         'style' => true,
    195169                ),
    196170                'h2' => array (
    197171                        'align' => true,
    198                         'class' => true,
    199                         'id'    => true,
    200                         'style' => true,
    201172                ),
    202173                'h3' => array (
    203174                        'align' => true,
    204                         'class' => true,
    205                         'id'    => true,
    206                         'style' => true,
    207175                ),
    208176                'h4' => array (
    209177                        'align' => true,
    210                         'class' => true,
    211                         'id'    => true,
    212                         'style' => true,
    213178                ),
    214179                'h5' => array (
    215180                        'align' => true,
    216                         'class' => true,
    217                         'id'    => true,
    218                         'style' => true,
    219181                ),
    220182                'h6' => array (
    221183                        'align' => true,
    222                         'class' => true,
    223                         'id'    => true,
    224                         'style' => true,
    225184                ),
    226185                'header' => array(
    227186                        'align' => true,
    228                         'class' => true,
    229187                        'dir' => true,
    230188                        'lang' => true,
    231                         'style' => true,
    232189                        'xml:lang' => true,
    233190                ),
    234191                'hgroup' => array(
    235192                        'align' => true,
    236                         'class' => true,
    237193                        'dir' => true,
    238194                        'lang' => true,
    239                         'style' => true,
    240195                        'xml:lang' => true,
    241196                ),
    242197                'hr' => array (
    243198                        'align' => true,
    244                         'class' => true,
    245199                        'noshade' => true,
    246200                        'size' => true,
    247201                        'width' => true,
    248202                ),
    249                 'i' => array(),
     203                'i' => array (),
    250204                'img' => array(
    251205                        'alt' => true,
    252206                        'align' => true,
    253207                        'border' => true,
    254                         'class' => true,
    255208                        'height' => true,
    256209                        'hspace' => true,
    257210                        'longdesc' => true,
    258211                        'vspace' => true,
    259212                        'src' => true,
    260                         'style' => true,
     213                        'usemap' => true,
    261214                        'width' => true,
    262215                ),
    263216                'ins' => array(
    264217                        'datetime' => true,
    265218                        'cite' => true,
    266219                ),
    267                 'kbd' => array(),
     220                'kbd' => array (),
    268221                'label' => array(
    269222                        'for' => true,
    270223                ),
     
    273226                ),
    274227                'li' => array (
    275228                        'align' => true,
    276                         'class' => true,
    277229                ),
     230                'map' => array(
     231                        'name' => true,
     232                ),
    278233                'menu' => array (
    279                         'class' => true,
    280                         'style' => true,
    281234                        'type' => true,
    282235                ),
    283236                'nav' => array(
    284237                        'align' => true,
    285                         'class' => true,
    286238                        'dir' => true,
    287239                        'lang' => true,
    288                         'style' => true,
    289240                        'xml:lang' => true,
    290241                ),
    291242                'p' => array(
    292                         'class' => true,
    293243                        'align' => true,
    294244                        'dir' => true,
    295245                        'lang' => true,
    296                         'style' => true,
    297246                        'xml:lang' => true,
    298247                ),
    299248                'pre' => array(
    300                         'style' => true,
    301249                        'width' => true,
    302250                ),
    303251                'q' => array(
     
    305253                ),
    306254                's' => array(),
    307255                'span' => array (
    308                         'class' => true,
    309256                        'dir' => true,
    310257                        'align' => true,
    311258                        'lang' => true,
    312                         'style' => true,
    313                         'title' => true,
    314259                        'xml:lang' => true,
    315260                ),
    316261                'section' => array(
    317262                        'align' => true,
    318                         'class' => true,
    319263                        'dir' => true,
    320264                        'lang' => true,
    321                         'style' => true,
    322265                        'xml:lang' => true,
    323266                ),
    324                 'small' => array(),
    325                 'strike' => array(),
    326                 'strong' => array(),
    327                 'sub' => array(),
     267                'small' => array (),
     268                'strike' => array (),
     269                'strong' => array (),
     270                'sub' => array (),
    328271                'summary' => array(
    329272                        'align' => true,
    330                         'class' => true,
    331273                        'dir' => true,
    332274                        'lang' => true,
    333                         'style' => true,
    334275                        'xml:lang' => true,
    335276                ),
    336                 'sup' => array(),
     277                'sup' => array (),
    337278                'table' => array(
    338279                        'align' => true,
    339280                        'bgcolor' => true,
    340281                        'border' => true,
    341282                        'cellpadding' => true,
    342283                        'cellspacing' => true,
    343                         'class' => true,
    344284                        'dir' => true,
    345                         'id' => true,
    346285                        'rules' => true,
    347                         'style' => true,
    348286                        'summary' => true,
    349287                        'width' => true,
    350288                ),
     
    361299                        'bgcolor' => true,
    362300                        'char' => true,
    363301                        'charoff' => true,
    364                         'class' => true,
    365302                        'colspan' => true,
    366303                        'dir' => true,
    367304                        'headers' => true,
     
    369306                        'nowrap' => true,
    370307                        'rowspan' => true,
    371308                        'scope' => true,
    372                         'style' => true,
    373309                        'valign' => true,
    374310                        'width' => true,
    375311                ),
     
    383319                'tfoot' => array(
    384320                        'align' => true,
    385321                        'char' => true,
    386                         'class' => true,
    387322                        'charoff' => true,
    388323                        'valign' => true,
    389324                ),
     
    394329                        'bgcolor' => true,
    395330                        'char' => true,
    396331                        'charoff' => true,
    397                         'class' => true,
    398332                        'colspan' => true,
    399333                        'headers' => true,
    400334                        'height' => true,
     
    408342                        'align' => true,
    409343                        'char' => true,
    410344                        'charoff' => true,
    411                         'class' => true,
    412345                        'valign' => true,
    413346                ),
    414347                'title' => array(),
     
    417350                        'bgcolor' => true,
    418351                        'char' => true,
    419352                        'charoff' => true,
    420                         'class' => true,
    421                         'style' => true,
    422353                        'valign' => true,
    423354                ),
    424                 'tt' => array(),
    425                 'u' => array(),
     355                'tt' => array (),
     356                'u' => array (),
    426357                'ul' => array (
    427                         'class' => true,
    428                         'style' => true,
    429358                        'type' => true,
    430359                ),
    431360                'ol' => array (
    432                         'class' => true,
    433361                        'start' => true,
    434                         'style' => true,
    435362                        'type' => true,
    436363                ),
    437364                'var' => array(),
     
    526453                'sdot',    'lceil',  'rceil',   'lfloor', 'rfloor', 'lang',
    527454                'rang',    'loz',    'spades',  'clubs',  'hearts', 'diams',
    528455        );
     456} else {
     457        $allowedtags = wp_kses_array_lc( $allowedtags );
     458        $allowedposttags = wp_kses_array_lc( $allowedposttags );
    529459}
    530460
    531461/**
     462 * Return a list of allowed tags and attributes for a given context.
     463 *
     464 * @since 3.5.0
     465 *
     466 * @param string $context The context for which to retrieve tags. Allowed values are
     467 *  post | strip | data | entities or the name of a field filter such as pre_user_description.
     468 * @return array List of allowed tags and their allowed attributes.
     469 */
     470function wp_kses_allowed_html( $context = '' ) {
     471        global $allowedposttags, $allowedtags, $allowedentitynames;
     472
     473        switch ( $context ) {
     474                case 'post':
     475                        return apply_filters( 'wp_kses_allowed_html', array_map( '_wp_add_global_attributes', $allowedposttags ), $context );
     476                        break;
     477                case 'user_description':
     478                case 'pre_user_description':
     479                        $tags = $allowedtags;
     480                        $tags['a']['rel'] = true;
     481                        return apply_filters( 'wp_kses_allowed_html', $tags, $context );
     482                        break;
     483                case 'strip':
     484                        return apply_filters( 'wp_kses_allowed_html', array(), $context );
     485                        break;
     486                case 'entities':
     487                        return apply_filters( 'wp_kses_allowed_html', $allowedentitynames, $context);
     488                        break;
     489                case 'data':
     490                default:
     491                        return apply_filters( 'wp_kses_allowed_html', $allowedtags, $context );
     492        }
     493}
     494
     495function _wp_add_global_attributes( $value ) {
     496        $global_attributes = array(
     497                'class' => true,
     498                'id' => true,
     499                'style' => true,
     500                'title' => true,
     501        );
     502
     503        if ( true === $value )
     504                $value = array();
     505
     506        if ( is_array( $value ) )
     507                return array_merge( $value, $global_attributes );
     508
     509        return $value;
     510}
     511
     512/**
    532513 * Filters content and keeps only allowable HTML elements.
    533514 *
    534515 * This function makes sure that only the allowed HTML element names, attribute
     
    554535        $string = wp_kses_no_null($string);
    555536        $string = wp_kses_js_entities($string);
    556537        $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);
     538        $string = wp_kses_hook($string, $allowed_html, $allowed_protocols); // WP changed the order of these funcs and added args to wp_kses_hook
     539        return wp_kses_split($string, $allowed_html, $allowed_protocols);
    560540}
    561541
    562542/**
     
    572552 * @param array $allowed_protocols Allowed protocol in links
    573553 * @return string Filtered content through 'pre_kses' hook
    574554 */
    575 function wp_kses_hook($string, $allowed_html, $allowed_protocols) {
     555function wp_kses_hook( $string, $allowed_html, $allowed_protocols ) {
    576556        $string = apply_filters('pre_kses', $string, $allowed_html, $allowed_protocols);
    577557        return $string;
    578558}
     
    600580 * @param array $allowed_protocols Allowed protocols to keep
    601581 * @return string Content with fixed HTML tags
    602582 */
    603 function wp_kses_split($string, $allowed_html, $allowed_protocols) {
     583function wp_kses_split( $string, $allowed_html, $allowed_protocols ) {
    604584        global $pass_allowed_html, $pass_allowed_protocols;
    605585        $pass_allowed_html = $allowed_html;
    606586        $pass_allowed_protocols = $allowed_protocols;
     
    668648        $elem = $matches[2];
    669649        $attrlist = $matches[3];
    670650
     651        if ( ! is_array( $allowed_html ) )
     652                $allowed_html = wp_kses_allowed_html( $allowed_html );
     653
    671654        if ( ! isset($allowed_html[strtolower($elem)]) )
    672655                return '';
    673656        # They are using a not allowed HTML element
     
    699682function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols) {
    700683        # Is there a closing XHTML slash at the end of the attributes?
    701684
     685        if ( ! is_array( $allowed_html ) )
     686                $allowed_html = wp_kses_allowed_html( $allowed_html );
     687
    702688        $xhtml_slash = '';
    703689        if (preg_match('%\s*/\s*$%', $attr))
    704690                $xhtml_slash = ' /';
     
    12861272 * @param string $data Content to filter, expected to be escaped with slashes
    12871273 * @return string Filtered content
    12881274 */
    1289 function wp_filter_kses($data) {
    1290         global $allowedtags;
    1291         return addslashes( wp_kses(stripslashes( $data ), $allowedtags) );
     1275function wp_filter_kses( $data ) {
     1276        return addslashes( wp_kses( stripslashes( $data ), current_filter() ) );
    12921277}
    12931278
    12941279/**
     
    13001285 * @param string $data Content to filter, expected to not be escaped
    13011286 * @return string Filtered content
    13021287 */
    1303 function wp_kses_data($data) {
    1304         global $allowedtags;
    1305         return wp_kses( $data , $allowedtags );
     1288function wp_kses_data( $data ) {
     1289        return wp_kses( $data , current_filter() );
    13061290}
    13071291
    13081292/**
     
    13121296 * data from forms.
    13131297 *
    13141298 * @since 2.0.0
    1315  * @uses $allowedposttags
    13161299 *
    13171300 * @param string $data Post content to filter, expected to be escaped with slashes
    13181301 * @return string Filtered post content with allowed HTML tags and attributes intact.
    13191302 */
    13201303function wp_filter_post_kses($data) {
    1321         global $allowedposttags;
    1322         return addslashes ( wp_kses(stripslashes( $data ), $allowedposttags) );
     1304        return addslashes ( wp_kses( stripslashes( $data ), 'post' ) );
    13231305}
    13241306
    13251307/**
     
    13291311 * data from forms.
    13301312 *
    13311313 * @since 2.9.0
    1332  * @uses $allowedposttags
    13331314 *
    13341315 * @param string $data Post content to filter
    13351316 * @return string Filtered post content with allowed HTML tags and attributes intact.
    13361317 */
    13371318function wp_kses_post($data) {
    1338         global $allowedposttags;
    1339         return wp_kses( $data , $allowedposttags );
     1319        return wp_kses( $data , 'post' );
    13401320}
    13411321
    13421322/**
     
    13471327 * @param string $data Content to strip all HTML from
    13481328 * @return string Filtered content without any HTML
    13491329 */
    1350 function wp_filter_nohtml_kses($data) {
    1351         return addslashes ( wp_kses(stripslashes( $data ), array()) );
     1330function wp_filter_nohtml_kses( $data ) {
     1331        return addslashes ( wp_kses( stripslashes( $data ), 'strip' ) );
    13521332}
    13531333
    13541334/**