Make WordPress Core

Ticket #37233: 37233.comment:31.patch

File 37233.comment:31.patch, 9.7 KB (added by rahulsprajapati, 9 years ago)

Refreshed Patch : decoded url paramter values as suggested in comment:31 by @afercia

  • src/wp-admin/js/updates.js

    diff --git a/src/wp-admin/js/updates.js b/src/wp-admin/js/updates.js
    index e1d963a..a8de967 100644
    a b  
    15971597                }
    15981598        };
    15991599
     1600        /**
     1601         * Handles the plugin searching from the repository dynamically.
     1602         *
     1603         * @param {object} data  $_POST data for ajax request 'search-install-plugins'.
     1604         *
     1605         */
     1606        wp.updates.pluginInstallSearchRequest = function ( data ) {
     1607                var $searchTab = $( '.plugin-install-search' ), searchLocation, $pluginFilter = $( '#plugin-filter' );
     1608
     1609                $pluginFilter.empty();
     1610
     1611                if ( ! $searchTab.length ) {
     1612
     1613                        searchLocation = location.href.split( '?' )[ 0 ] + '?' + $.param( _.omit( data, [ '_ajax_nonce', 'pagenow' ] ) );
     1614
     1615                        $searchTab = $( '<li class="plugin-install-search" />' )
     1616                                .append( $( '<a />', {
     1617                                        'class': 'current',
     1618                                        'href': searchLocation,
     1619                                        'text': wp.updates.l10n.searchResultsLabel
     1620                                } ) );
     1621
     1622                        $( '.wp-filter .filter-links .current' )
     1623                                .removeClass( 'current' )
     1624                                .parents( '.filter-links' )
     1625                                .prepend( $searchTab );
     1626
     1627                        $pluginFilter.prev( 'p' ).remove();
     1628
     1629                        $( '.plugins-popular-tags-wrapper' ).remove();
     1630                }
     1631
     1632                if ( 'undefined' !== typeof wp.updates.searchRequest ) {
     1633                        wp.updates.searchRequest.abort();
     1634                }
     1635
     1636                $( 'body' ).addClass( 'loading-content' );
     1637
     1638                wp.updates.searchRequest = wp.ajax.post( 'search-install-plugins', data ).done( function( response ) {
     1639                        $( 'body' ).removeClass( 'loading-content' );
     1640                        $pluginFilter.append( response.items );
     1641                        delete wp.updates.searchRequest;
     1642
     1643                        if ( 0 === response.count ) {
     1644                                wp.a11y.speak( wp.updates.l10n.noPluginsFound );
     1645                        } else {
     1646                                wp.a11y.speak( wp.updates.l10n.pluginsFound.replace( '%d', response.count ) );
     1647                        }
     1648                } );
     1649        };
     1650
     1651        /**
     1652         * Handles the plugin searching from install plugins.
     1653         *
     1654         * @param {object} data  $_POST data for ajax request 'search-plugins'.
     1655         *
     1656         */
     1657        wp.updates.pluginSearchRequest = function ( data ) {
     1658                var $bulkActionForm      = $( '#bulk-action-form' );
     1659                if ( 'undefined' !== typeof wp.updates.searchRequest ) {
     1660                        wp.updates.searchRequest.abort();
     1661                }
     1662
     1663                $bulkActionForm.empty();
     1664
     1665                $( 'body' ).addClass( 'loading-content' );
     1666
     1667                wp.updates.searchRequest = wp.ajax.post( 'search-plugins', data ).done( function ( response ) {
     1668
     1669                        // Can we just ditch this whole subtitle business?
     1670                        var $subTitle = $( '<span />' ).addClass( 'subtitle' ).html( wp.updates.l10n.searchResults.replace( '%s', _.escape( data.s ) ) ), $oldSubTitle = $( '.wrap .subtitle' );
     1671
     1672                        if ( ! data.s.length ) {
     1673                                $oldSubTitle.remove();
     1674                        } else if ( $oldSubTitle.length ) {
     1675                                $oldSubTitle.replaceWith( $subTitle );
     1676                        } else {
     1677                                $( '.wrap h1' ).append( $subTitle );
     1678                        }
     1679
     1680                        $( 'body' ).removeClass( 'loading-content' );
     1681                        $bulkActionForm.append( response.items );
     1682                        delete wp.updates.searchRequest;
     1683
     1684                        if ( 0 === response.count ) {
     1685                                wp.a11y.speak( wp.updates.l10n.noPluginsFound );
     1686                        } else {
     1687                                wp.a11y.speak( wp.updates.l10n.pluginsFound.replace( '%d', response.count ) );
     1688                        }
     1689                } );
     1690        };
     1691
    16001692        $( function() {
    16011693                var $pluginFilter        = $( '#plugin-filter' ),
    16021694                        $bulkActionForm      = $( '#bulk-action-form' ),
    16031695                        $filesystemModal     = $( '#request-filesystem-credentials-dialog' ),
    16041696                        $pluginSearch        = $( '.plugins-php .wp-filter-search' ),
    1605                         $pluginInstallSearch = $( '.plugin-install-php .wp-filter-search' );
     1697                        $pluginInstallSearch = $( '.plugin-install-php .wp-filter-search' ),
     1698                        $pluginSearchType    = $( '#typeselector' );
    16061699
    16071700                /*
    16081701                 * Whether a user needs to submit filesystem credentials.
     
    20332126                 * @since 4.6.0
    20342127                 */
    20352128                $pluginInstallSearch.on( 'keyup input', _.debounce( function( event, eventtype ) {
    2036                         var $searchTab = $( '.plugin-install-search' ), data, searchLocation;
     2129                        var data, searchLocation;
    20372130
    20382131                        data = {
    20392132                                _ajax_nonce: wp.updates.ajaxNonce,
    20402133                                s:           event.target.value,
    20412134                                tab:         'search',
    2042                                 type:        $( '#typeselector' ).val(),
     2135                                type:        $pluginSearchType.val(),
    20432136                                pagenow:     pagenow
    20442137                        };
    20452138                        searchLocation = location.href.split( '?' )[ 0 ] + '?' + $.param( _.omit( data, [ '_ajax_nonce', 'pagenow' ] ) );
     
    20522145                        if ( wp.updates.searchTerm === data.s && 'typechange' !== eventtype ) {
    20532146                                return;
    20542147                        } else {
    2055                                 $pluginFilter.empty();
    20562148                                wp.updates.searchTerm = data.s;
    20572149                        }
    20582150
     
    20602152                                window.history.pushState( null, '', searchLocation );
    20612153                        }
    20622154
    2063                         if ( ! $searchTab.length ) {
    2064                                 $searchTab = $( '<li class="plugin-install-search" />' )
    2065                                         .append( $( '<a />', {
    2066                                                 'class': 'current',
    2067                                                 'href': searchLocation,
    2068                                                 'text': wp.updates.l10n.searchResultsLabel
    2069                                         } ) );
    2070 
    2071                                 $( '.wp-filter .filter-links .current' )
    2072                                         .removeClass( 'current' )
    2073                                         .parents( '.filter-links' )
    2074                                         .prepend( $searchTab );
    2075 
    2076                                 $pluginFilter.prev( 'p' ).remove();
    2077                                 $( '.plugins-popular-tags-wrapper' ).remove();
    2078                         }
    2079 
    2080                         if ( 'undefined' !== typeof wp.updates.searchRequest ) {
    2081                                 wp.updates.searchRequest.abort();
    2082                         }
    2083                         $( 'body' ).addClass( 'loading-content' );
    2084 
    2085                         wp.updates.searchRequest = wp.ajax.post( 'search-install-plugins', data ).done( function( response ) {
    2086                                 $( 'body' ).removeClass( 'loading-content' );
    2087                                 $pluginFilter.append( response.items );
    2088                                 delete wp.updates.searchRequest;
     2155                        wp.updates.pluginInstallSearchRequest( data );
    20892156
    2090                                 if ( 0 === response.count ) {
    2091                                         wp.a11y.speak( wp.updates.l10n.noPluginsFound );
    2092                                 } else {
    2093                                         wp.a11y.speak( wp.updates.l10n.pluginsFound.replace( '%d', response.count ) );
    2094                                 }
    2095                         } );
    20962157                }, 500 ) );
    20972158
    20982159                if ( $pluginSearch.length ) {
     
    21272188                                window.history.pushState( null, '', location.href.split( '?' )[ 0 ] + '?s=' + data.s );
    21282189                        }
    21292190
    2130                         if ( 'undefined' !== typeof wp.updates.searchRequest ) {
    2131                                 wp.updates.searchRequest.abort();
    2132                         }
    2133 
    2134                         $bulkActionForm.empty();
    2135                         $( 'body' ).addClass( 'loading-content' );
    2136 
    2137                         wp.updates.searchRequest = wp.ajax.post( 'search-plugins', data ).done( function( response ) {
    2138 
    2139                                 // Can we just ditch this whole subtitle business?
    2140                                 var $subTitle    = $( '<span />' ).addClass( 'subtitle' ).html( wp.updates.l10n.searchResults.replace( '%s', _.escape( data.s ) ) ),
    2141                                         $oldSubTitle = $( '.wrap .subtitle' );
    2142 
    2143                                 if ( ! data.s.length ) {
    2144                                         $oldSubTitle.remove();
    2145                                 } else if ( $oldSubTitle.length ) {
    2146                                         $oldSubTitle.replaceWith( $subTitle );
    2147                                 } else {
    2148                                         $( '.wrap h1' ).append( $subTitle );
    2149                                 }
    2150 
    2151                                 $( 'body' ).removeClass( 'loading-content' );
    2152                                 $bulkActionForm.append( response.items );
    2153                                 delete wp.updates.searchRequest;
     2191                        wp.updates.pluginSearchRequest( data );
    21542192
    2155                                 if ( 0 === response.count ) {
    2156                                         wp.a11y.speak( wp.updates.l10n.noPluginsFound );
    2157                                 } else {
    2158                                         wp.a11y.speak( wp.updates.l10n.pluginsFound.replace( '%d', response.count ) );
    2159                                 }
    2160                         } );
    21612193                }, 500 ) );
    21622194
    21632195                /**
     
    21762208                 *
    21772209                 * @since 4.6.0
    21782210                 */
    2179                 $( '#typeselector' ).on( 'change', function() {
     2211                $pluginSearchType.on( 'change', function() {
    21802212                        var $search = $( 'input[name="s"]' );
    21812213
    21822214                        if ( $search.val().length ) {
     
    22982330                 * @since 4.2.0
    22992331                 */
    23002332                $( window ).on( 'beforeunload', wp.updates.beforeunload );
     2333
     2334                /**
     2335                 * Window popstate for search plugins
     2336                 */
     2337                $( window ).on( 'popstate', function ( event ) {
     2338
     2339                        if ( 'plugin-install' === pagenow || 'plugins' === pagenow ) {
     2340                                var data, currentLocation, urlSearchString, urlTypeString, urlTabString;
     2341                                currentLocation = location.href;
     2342                                urlSearchString = wp.urlParam( 's', currentLocation );
     2343
     2344                                switch ( pagenow ) {
     2345
     2346                                        case 'plugins':
     2347
     2348                                                $pluginSearch.val( urlSearchString );
     2349
     2350                                                data = {
     2351                                                        _ajax_nonce: wp.updates.ajaxNonce,
     2352                                                        s:           urlSearchString,
     2353                                                        pagenow:     pagenow
     2354                                                };
     2355
     2356                                                wp.updates.pluginSearchRequest( data );
     2357                                                break;
     2358
     2359                                        case 'plugin-install':
     2360
     2361                                                urlTypeString   = wp.urlParam( 'type', currentLocation );
     2362                                                urlTabString    = wp.urlParam( 'tab', currentLocation );
     2363
     2364                                                if ( urlTypeString == "" ) {
     2365                                                        urlTypeString = "term";
     2366                                                }
     2367                                                $pluginSearchType.val( urlTypeString );
     2368                                                $pluginInstallSearch.val( urlSearchString );
     2369
     2370                                                data = {
     2371                                                        _ajax_nonce: wp.updates.ajaxNonce,
     2372                                                        s:           urlSearchString,
     2373                                                        tab:         urlTabString,
     2374                                                        type:        urlTypeString,
     2375                                                        pagenow:     pagenow
     2376                                                };
     2377
     2378                                                wp.updates.pluginInstallSearchRequest( data );
     2379                                                break;
     2380
     2381                                        default:
     2382                                                return;
     2383                                }
     2384                        }
     2385
     2386                } );
    23012387        } );
    23022388})( jQuery, window.wp, _.extend( window._wpUpdatesSettings, window._wpUpdatesItemCounts || {} ) );
  • src/wp-includes/js/wp-util.js

    diff --git a/src/wp-includes/js/wp-util.js b/src/wp-includes/js/wp-util.js
    index 527441d..557ec20 100644
    a b window.wp = window.wp || {}; 
    66        var settings = typeof _wpUtilSettings === 'undefined' ? {} : _wpUtilSettings;
    77
    88        /**
     9         * wp.urlParam( name, url )
     10         *
     11         * Fetch parameters from given URL
     12         *
     13         * @param  {string} name   A parameter name to fetch value from url.
     14         *                       For example, "param1" for example.com?param1=value1&param2=value2
     15         *
     16         * @param  {string} url   Url to fetch parameters
     17         *                       For example, example.com?param1=value1&param2=value2
     18         *
     19         * @return {string}   Return value of given parameter name from url
     20         */
     21        wp.urlParam = function ( name, url ) {
     22                var results = new RegExp( '[\?&]' + name + '=([^&#]*)' ).exec( decodeURIComponent( url ) );
     23                if ( 'undefined' === typeof results || null == results || ! _.isArray( results ) || 'undefined' === typeof results[1] ) {
     24                        return "";
     25                }
     26                return results[1].replace(/\+/g, " ");
     27        };
     28
     29
     30        /**
    931         * wp.template( id )
    1032         *
    1133         * Fetch a JavaScript template for an id, and return a templating function for it.