Make WordPress Core

Ticket #31528: 31528.3.diff

File 31528.3.diff, 11.6 KB (added by jorbin, 10 years ago)
  • src/wp-admin/css/forms.css

     
    850850        margin-bottom: 5px;
    851851}
    852852
     853/*------------------------------------------------------------------------------
     854   Credentials check dialog for Install and Updates
     855------------------------------------------------------------------------------*/
     856
     857.request-filesystem-credentials-dialog {
     858        display: none;
     859}
     860
     861.request-filesystem-credentials-dialog .notification-dialog{
     862        top: 15%
     863}
     864
     865.request-filesystem-credentials-dialog-content{
     866        margin: 25px;
     867}
     868
    853869/* =Media Queries
    854870-------------------------------------------------------------- */
    855871
  • src/wp-admin/includes/ajax-actions.php

     
    29132913        if ( is_wp_error( $result ) ) {
    29142914                $status['error'] = $result->get_error_message();
    29152915                wp_send_json_error( $status );
     2916        } else if ( is_null( $result ) ) {
     2917                $status['errorCode'] = __( 'unable_to_connect_to_filesystem' );
     2918                $status['error'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
     2919                wp_send_json_error( $status );
    29162920        }
    29172921
    29182922        $plugin_status = install_plugin_install_status( $api );
     
    29542958
    29552959        $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
    29562960        $result = $upgrader->bulk_upgrade( array( $plugin ) );
    2957 
    29582961        if ( is_array( $result ) ) {
    2959                 $result = $result[ $plugin ];
    2960         }
    2961 
    2962         if ( is_wp_error( $result ) ) {
     2962                wp_send_json_success( $status );
     2963        } else if ( is_wp_error( $result ) ) {
    29632964                $status['error'] = $result->get_error_message();
    29642965                wp_send_json_error( $status );
     2966        } else if ( is_bool( $result ) && ! $result ) {
     2967                $status['errorCode'] = __( 'unable_to_connect_to_filesystem' );
     2968                $status['error'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
     2969                wp_send_json_error( $status );
    29652970        }
    2966 
    2967         wp_send_json_success( $status );
    29682971}
    29692972
    29702973/**
  • src/wp-admin/js/updates.js

     
    2222        wp.updates.l10n = window._wpUpdatesSettings.l10n;
    2323
    2424        /**
     25         * Whether filesystem credentials need to be requested from the user.
     26         *
     27         * @since 4.2.0
     28         *
     29         * @var bool
     30         */
     31        wp.updates.shouldRequestFilesystemCredentials = window._wpUpdatesSettings.requestFilesystemCredentials;
     32
     33        /**
     34         * Filesystem credentials to be packaged along with the request.
     35         *
     36         * @since  4.2.0
     37         *
     38         * @var object
     39         */
     40        wp.updates.filesystemCredentials = {
     41                ftp: {
     42                        host: null,
     43                        username: null,
     44                        password: null,
     45                        connectionType: null
     46                },
     47                ssh: {
     48                        publicKey: null,
     49                        privateKey: null
     50                }
     51        };
     52
     53        /**
    2554         * Flag if we're waiting for an install/update to complete.
    2655         *
    2756         * @since 4.2.0
     
    3160        wp.updates.updateLock = false;
    3261
    3362        /**
     63         * Flag if we've done an install or update successfully.
     64         *
     65         * @since 4.2.0
     66         *
     67         * @var bool
     68         */
     69        wp.updates.updateDoneSuccessfully = false;
     70
     71        /**
    3472         * If the user tries to install/update a plugin while an install/update is
    3573         * already happening, it can be placed in this queue to perform later.
    3674         *
     
    124162
    125163                var data = {
    126164                        '_ajax_nonce': wp.updates.ajaxNonce,
    127                         'plugin':      plugin,
    128                         'slug':        slug
     165                        'plugin':        plugin,
     166                        'slug':          slug,
     167                        username:        wp.updates.filesystemCredentials.ftp.username,
     168                        password:        wp.updates.filesystemCredentials.ftp.password,
     169                        hostname:        wp.updates.filesystemCredentials.ftp.hostname,
     170                        connection_type: wp.updates.filesystemCredentials.ftp.connectionType,
     171                        public_key:      wp.updates.filesystemCredentials.ssh.publicKey,
     172                        private_key:     wp.updates.filesystemCredentials.ssh.privateKey
    129173                };
    130174
    131175                wp.ajax.post( 'update-plugin', data )
     
    157201                wp.a11y.speak( wp.updates.l10n.updatedMsg );
    158202
    159203                wp.updates.decrementCount( 'plugin' );
     204
     205                wp.updates.updateDoneSuccessfully = true;
    160206        };
    161207
    162208        /**
     
    168214         */
    169215        wp.updates.updateError = function( response ) {
    170216                var $message;
     217                wp.updates.updateDoneSuccessfully = false;
     218                if ( response.errorCode && response.errorCode == 'unable_to_connect_to_filesystem' ) {
     219                        wp.updates.updateQueue.push( {
     220                                type: 'update-plugin',
     221                                data: {
     222                                        // Not cool that we're depending on response for this data.
     223                                        // This would feel more whole in a view all tied together.
     224                                        plugin: response.plugin,
     225                                        slug: response.slug
     226                                }
     227                        } );
     228            wp.updates.showErrorInCredentialsForm( response.error );
     229                        wp.updates.requestFilesystemCredentials();
     230                        return;
     231                }
    171232                if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
    172233                        $message = $( '#' + response.slug ).next().find( '.update-message' );
    173234                } else if ( 'plugin-install' === pagenow ) {
     
    179240        };
    180241
    181242        /**
     243         * Show an
     244         *
     245         * @param {string} message
     246         * @since 4.2.0
     247         */
     248        wp.updates.showErrorInCredentialsForm = function( message ) {
     249        var $notificationDialog = $( '.notification-dialog' );
     250       
     251                // Remove any existing error
     252                $notificationDialog.find( '.error' ).remove();
     253
     254                $notificationDialog.find( 'h3' ).after( '<div class="error">' + message + '</div>' );
     255
     256    }
     257
     258        /**
    182259         * After an update attempt has completed, check the queue.
    183260         *
    184261         * @since 4.2.0
     
    216293                wp.updates.updateLock = true;
    217294
    218295                var data = {
    219                         '_ajax_nonce': wp.updates.ajaxNonce,
    220                         'slug':        slug
     296                        '_ajax_nonce':     wp.updates.ajaxNonce,
     297                        'slug':            slug,
     298                        'username':        wp.updates.filesystemCredentials.ftp.username,
     299                        'password':        wp.updates.filesystemCredentials.ftp.password,
     300                        'hostname':        wp.updates.filesystemCredentials.ftp.hostname,
     301                        'connection_type': wp.updates.filesystemCredentials.ftp.connectionType,
     302                        'public_key':      wp.updates.filesystemCredentials.ssh.publicKey,
     303                        'private_key':     wp.updates.filesystemCredentials.ssh.privateKey
    221304                };
    222305
    223306                wp.ajax.post( 'install-plugin', data )
     
    239322                $message.removeClass( 'updating-message' ).addClass( 'updated-message button-disabled' );
    240323                $message.text( wp.updates.l10n.installed );
    241324                wp.a11y.speak( wp.updates.l10n.installedMsg );
     325                wp.updates.updateDoneSuccessfully = true;
    242326        };
    243327
    244328        /**
     
    250334         */
    251335        wp.updates.installError = function( response ) {
    252336                var $message = $( '.plugin-card-' + response.slug ).find( '.install-now' );
     337                wp.updates.updateDoneSuccessfully = false;
     338                if ( response.errorCode && response.errorCode == 'unable_to_connect_to_filesystem' ) {
     339                        wp.updates.updateQueue.push( {
     340                                type: 'update-plugin',
     341                                data: {
     342                                        // Not cool that we're depending on response for this data.
     343                                        // This would feel more whole in a view all tied together.
     344                                        plugin: response.plugin,
     345                                        slug: response.slug
     346                                }
     347                        } );
     348            wp.updates.showErrorInCredentialsForm( response.error );
     349                        wp.updates.requestFilesystemCredentials();
     350                        return;
     351                }
    253352
    254353                $message.removeClass( 'updating-message' );
    255354                $message.text( wp.updates.l10n.installNow );
     
    281380                                break;
    282381                }
    283382        };
     383        /**
     384         * Request the users filesystem credentials if we don't have them already
     385         *
     386         * @since 4.2.0
     387         */
     388        wp.updates.requestFilesystemCredentials = function() {
     389                if ( wp.updates.updateDoneSuccessfully === false ) {
     390                        wp.updates.updateLock = true;
     391                        $('#request-filesystem-credentials-dialog').show();
     392                }
     393        };
    284394
     395        // Bind various click handlers.
    285396        $( document ).ready( function() {
     397                // File system credentials form submit noop-er / handler.
     398                $('#request-filesystem-credentials-dialog form').on( 'submit', function() {
     399                        // Persist the credentials input by the user for the duration of the page load.
     400                        wp.updates.filesystemCredentials.ftp.hostname = $('#hostname').val();
     401                        wp.updates.filesystemCredentials.ftp.username = $('#username').val();
     402                        wp.updates.filesystemCredentials.ftp.password = $('#password').val();
     403                        wp.updates.filesystemCredentials.ftp.connectionType = $('input[name="connection_type"]:checked').val();
     404                        wp.updates.filesystemCredentials.ssh.publicKey = $('#public_key').val();
     405                        wp.updates.filesystemCredentials.ssh.privateKey = $('#private_key').val();
     406
     407                        $('#request-filesystem-credentials-dialog').hide();
     408
     409                        // Unlock and invoke the queue.
     410                        wp.updates.updateLock = false;
     411                        wp.updates.queueChecker();
     412
     413                        return false;
     414                });
     415
     416                // Click handler for plugin updates in List Table view.
    286417                $( '.plugin-update-tr .update-link' ).on( 'click', function( e ) {
    287418                        e.preventDefault();
     419                        if ( wp.updates.shouldRequestFilesystemCredentials ) {
     420                                wp.updates.requestFilesystemCredentials();
     421                        }
    288422                        var $row = $( e.target ).parents( '.plugin-update-tr' );
    289423                        wp.updates.updatePlugin( $row.data( 'plugin' ), $row.data( 'slug' ) );
    290424                } );
     
    315449
    316450                $( '.plugin-card .install-now' ).on( 'click', function( e ) {
    317451                        e.preventDefault();
     452                        if ( wp.updates.shouldRequestFilesystemCredentials ) {
     453                                wp.updates.requestFilesystemCredentials();
     454                        }
     455
    318456                        var $button = $( e.target );
    319457                        if ( $button.hasClass( 'button-disabled' ) ) {
    320458                                return;
  • src/wp-admin/plugin-install.php

     
    128128 */
    129129do_action( "install_plugins_$tab", $paged ); ?>
    130130</div>
     131
     132<div id="request-filesystem-credentials-dialog" class="notification-dialog-wrap request-filesystem-credentials-dialog">
     133        <div class="notification-dialog-background"></div>
     134        <div class="notification-dialog">
     135                <div class="request-filesystem-credentials-dialog-content">
     136                        <?php request_filesystem_credentials( site_url() ); ?>
     137                <div>
     138        </div>
     139</div>
     140
    131141<?php
    132142/**
    133143 * WordPress Administration Template Footer.
  • src/wp-admin/plugins.php

     
    475475
    476476</div>
    477477
     478<div id="request-filesystem-credentials-dialog" class="notification-dialog-wrap request-filesystem-credentials-dialog">
     479        <div class="notification-dialog-background"></div>
     480        <div class="notification-dialog">
     481                <div class="request-filesystem-credentials-dialog-content">
     482                        <?php request_filesystem_credentials( site_url() ); ?>
     483                <div>
     484        </div>
     485</div>
    478486<?php
    479487include(ABSPATH . 'wp-admin/admin-footer.php');
  • src/wp-includes/script-loader.php

     
    542542                ) );
    543543
    544544                $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y' ) );
     545
     546                /*
     547                 * Determine whether the user will need to enter filesystem credentials
     548                 * on the front-end.
     549                 */
     550                $filesystem_method = get_filesystem_method();
     551                ob_start();
     552                $filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() );
     553                ob_end_clean();
     554                $request_filesystem_credentials = ( $filesystem_method != 'direct' && ! $filesystem_credentials_are_stored ) ? 1 : 0;
     555
    545556                did_action( 'init' ) && $scripts->localize( 'updates', '_wpUpdatesSettings', array(
    546557                        'ajax_nonce' => wp_create_nonce( 'updates' ),
     558                        'requestFilesystemCredentials' => $request_filesystem_credentials,
    547559                        'l10n'       => array(
    548560                                'updating'      => __( 'Updating...' ),
    549561                                'updated'       => __( 'Updated!' ),