Make WordPress Core

Ticket #50612: 50612.diff

File 50612.diff, 7.8 KB (added by azaozz, 5 years ago)
  • src/js/_enqueues/admin/common.js

     
    16061606        });
    16071607});
    16081608
     1609// On the "Update plugin/theme from uploaded zip" screen
     1610// hide the "Replace current with uploaded" button and show a warning in 1 hour and 59 minutes.
     1611$document.ready( function( $ ) {
     1612        var $overwrite, $warning;
     1613
     1614        if ( ! $body.hasClass( 'update-php' ) ) {
     1615                return;
     1616        }
     1617
     1618        $overwrite = $( 'a.update-from-upload-overwrite' );
     1619        $warning   = $( '.update-from-upload-expired' );
     1620
     1621        if ( ! $overwrite.length || ! $warning.length ) {
     1622                return;
     1623        }
     1624
     1625        window.setTimeout(
     1626                function() {
     1627                        $overwrite.hide();
     1628                        $warning.removeClass( 'hidden' );
     1629
     1630                        if ( window.wp && window.wp.a11y ) {
     1631                                window.wp.a11y.speak( $warning.text() );
     1632                        }
     1633                },
     1634                7140000 // 119 minutes. The uploaded file is deleted after 2 hours.
     1635        );
     1636} );
     1637
    16091638// Fire a custom jQuery event at the end of window resize.
    16101639( function() {
    16111640        var timeout;
  • src/wp-admin/includes/class-plugin-installer-skin.php

     
    292292                        $overwrite = $this->is_downgrading ? 'downgrade-plugin' : 'update-plugin';
    293293
    294294                        $install_actions['ovewrite_plugin'] = sprintf(
    295                                 '<a class="button button-primary" href="%s" target="_parent">%s</a>',
     295                                '<a class="button button-primary update-from-upload-overwrite" href="%s" target="_parent">%s</a>',
    296296                                wp_nonce_url( add_query_arg( 'overwrite', $overwrite, $this->url ), 'plugin-upload' ),
    297                                 esc_html( __( 'Replace current with uploaded' ) )
     297                                __( 'Replace current with uploaded' )
    298298                        );
    299299                } else {
    300300                        echo $blocked_message;
    301301                }
    302302
     303                $cancel_url = add_query_arg( 'action', 'upload-plugin-cancel-overwrite', $this->url );
     304
    303305                $install_actions['plugins_page'] = sprintf(
    304306                        '<a class="button" href="%s">%s</a>',
    305                         self_admin_url( 'plugin-install.php' ),
     307                        wp_nonce_url( $cancel_url, 'plugin-upload-cancel-overwrite' ),
    306308                        __( 'Cancel and go back' )
    307309                );
    308310
     
    318320                $install_actions = apply_filters( 'install_plugin_ovewrite_actions', $install_actions, $this->api, $this->upgrader->new_plugin_data );
    319321
    320322                if ( ! empty( $install_actions ) ) {
     323                        printf(
     324                                '<p class="update-from-upload-expired hidden">%s</p>',
     325                                __( 'The uploaded file has expired. Please go back and upload it again.' )
     326                        );
    321327                        echo '<p class="update-from-upload-actions">' . implode( ' ', (array) $install_actions ) . '</p>';
    322328                }
    323329
  • src/wp-admin/includes/class-theme-installer-skin.php

     
    321321                        $overwrite = $this->is_downgrading ? 'downgrade-theme' : 'update-theme';
    322322
    323323                        $install_actions['ovewrite_theme'] = sprintf(
    324                                 '<a class="button button-primary" href="%s" target="_parent">%s</a>',
     324                                '<a class="button button-primary update-from-upload-overwrite" href="%s" target="_parent">%s</a>',
    325325                                wp_nonce_url( add_query_arg( 'overwrite', $overwrite, $this->url ), 'theme-upload' ),
    326                                 esc_html( __( 'Replace current with uploaded' ) )
     326                                __( 'Replace current with uploaded' )
    327327                        );
    328328                } else {
    329329                        echo $blocked_message;
    330330                }
    331331
     332                $cancel_url = add_query_arg( 'action', 'upload-theme-cancel-overwrite', $this->url );
     333
    332334                $install_actions['themes_page'] = sprintf(
    333335                        '<a class="button" href="%s" target="_parent">%s</a>',
    334                         self_admin_url( 'theme-install.php' ),
     336                        wp_nonce_url( $cancel_url, 'theme-upload-cancel-overwrite' ),
    335337                        __( 'Cancel and go back' )
    336338                );
    337339
     
    347349                $install_actions = apply_filters( 'install_theme_ovewrite_actions', $install_actions, $this->api, $this->upgrader->new_theme_data );
    348350
    349351                if ( ! empty( $install_actions ) ) {
     352                        printf(
     353                                '<p class="update-from-upload-expired hidden">%s</p>',
     354                                __( 'The uploaded file has expired. Please go back and upload it again.' )
     355                        );
    350356                        echo '<p class="update-from-upload-actions">' . implode( ' ', (array) $install_actions ) . '</p>';
    351357                }
    352358
  • src/wp-admin/includes/class-wp-media-list-table.php

     
    6969        public function prepare_items() {
    7070                global $wp_query, $post_mime_types, $avail_post_mime_types, $mode;
    7171
     72                // Exclude attachments scheduled for deletion in the next two hours
     73                // if they are for zip packages for interrupted or failed updates.
     74                // See File_Upload_Upgrader class.
     75                $not_in = array();
     76
     77                foreach ( _get_cron_array() as $cron ) {
     78                        if ( isset( $cron['upgrader_scheduled_cleanup'] ) ) {
     79                                $details = reset( $cron['upgrader_scheduled_cleanup'] );
     80
     81                                if ( ! empty( $details['args'][0] ) ) {
     82                                        $not_in[] = (int) $details['args'][0];
     83                                }
     84                        }
     85                }
     86
     87                if ( ! empty( $_REQUEST['post__not_in'] ) && is_array( $_REQUEST['post__not_in'] ) ) {
     88                        $not_in = array_merge( array_values( $_REQUEST['post__not_in'] ), $not_in );
     89                }
     90
     91                if ( ! empty( $not_in ) ) {
     92                        $_REQUEST['post__not_in'] = $not_in;
     93                }
     94
    7295                list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $_REQUEST );
    7396
    7497                $this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter'];
  • src/wp-admin/update.php

     
    1717
    1818require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    1919
     20wp_enqueue_script( 'wp-a11y' );
     21
    2022if ( isset( $_GET['action'] ) ) {
    2123        $plugin = isset( $_REQUEST['plugin'] ) ? trim( $_REQUEST['plugin'] ) : '';
    2224        $theme  = isset( $_REQUEST['theme'] ) ? urldecode( $_REQUEST['theme'] ) : '';
     
    174176
    175177                require_once ABSPATH . 'wp-admin/admin-footer.php';
    176178
     179        } elseif ( 'upload-plugin-cancel-overwrite' === $action ) {
     180                if ( ! current_user_can( 'upload_plugins' ) ) {
     181                        wp_die( __( 'Sorry, you are not allowed to install plugins on this site.' ) );
     182                }
     183
     184                check_admin_referer( 'plugin-upload-cancel-overwrite' );
     185
     186                // Make sure the attachment still exists, or File_Upload_Upgrader will call wp_die()
     187                // that shows a generic "Please select a file" error.
     188                if ( ! empty( $_GET['package'] ) ) {
     189                        $attachment_id = (int) $_GET['package'];
     190
     191                        if ( get_post( $attachment_id ) ) {
     192                                $file_upload = new File_Upload_Upgrader( 'pluginzip', 'package' );
     193                                $file_upload->cleanup();
     194                        }
     195                }
     196
     197                wp_redirect( self_admin_url( 'plugin-install.php' ) );
     198                exit;
    177199        } elseif ( 'upgrade-theme' === $action ) {
    178200
    179201                if ( ! current_user_can( 'update_themes' ) ) {
     
    297319
    298320                require_once ABSPATH . 'wp-admin/admin-footer.php';
    299321
     322        } elseif ( 'upload-theme-cancel-overwrite' === $action ) {
     323                if ( ! current_user_can( 'upload_themes' ) ) {
     324                        wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) );
     325                }
     326
     327                check_admin_referer( 'theme-upload-cancel-overwrite' );
     328
     329                // Make sure the attachment still exists, or File_Upload_Upgrader will call wp_die()
     330                // that shows a generic "Please select a file" error.
     331                if ( ! empty( $_GET['package'] ) ) {
     332                        $attachment_id = (int) $_GET['package'];
     333
     334                        if ( get_post( $attachment_id ) ) {
     335                                $file_upload = new File_Upload_Upgrader( 'themezip', 'package' );
     336                                $file_upload->cleanup();
     337                        }
     338                }
     339
     340                wp_redirect( self_admin_url( 'theme-install.php' ) );
     341                exit;
    300342        } else {
    301343                /**
    302344                 * Fires when a custom plugin or theme update request is received.