From 81d600dcca3d1326a5c0c72f8fa881c75069e877 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Tue, 2 Sep 2014 18:07:18 +0000 Subject: [PATCH] Install: Only show the language chooser when we have access to the filesystem without asking for credentials. fixes #29397. Built from https://develop.svn.wordpress.org/trunk@29673 git-svn-id: http://core.svn.wordpress.org/trunk@29448 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/translation-install.php | 34 +++++++++++++++++++++-- wp-admin/install.php | 2 +- wp-admin/setup-config.php | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/wp-admin/includes/translation-install.php b/wp-admin/includes/translation-install.php index 1c60474b71..f3cc370ac4 100644 --- a/wp-admin/includes/translation-install.php +++ b/wp-admin/includes/translation-install.php @@ -204,9 +204,37 @@ function wp_download_language_pack( $download ) { $skin = new Automatic_Upgrader_Skin; $upgrader = new Language_Pack_Upgrader( $skin ); $translation->type = 'core'; - /** - * @todo failures (such as non-direct FS) - */ $result = $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) ); + + if ( ! $result || is_wp_error( $result ) ) { + return false; + } + return $translation->language; } + +/** + * Check if WordPress has access to the filesystem without asking for + * credentials. + * + * @since 4.0.0 + * + * @return bool Returns true on success, false on failure. + */ +function wp_can_install_language_pack() { + if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) { + return false; + } + + require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; + $skin = new Automatic_Upgrader_Skin; + $upgrader = new Language_Pack_Upgrader( $skin ); + + $check = $upgrader->fs_connect( array( WP_CONTENT_DIR, WP_LANG_DIR ) ); + + if ( ! $check || is_wp_error( $check ) ) { + return false; + } + + return true; +} diff --git a/wp-admin/install.php b/wp-admin/install.php index cce438ec4c..8509eeaf3a 100644 --- a/wp-admin/install.php +++ b/wp-admin/install.php @@ -189,7 +189,7 @@ if ( ! empty( $_REQUEST['language'] ) ) { switch($step) { case 0: // Step 0 - if ( empty( $langugage ) && ( $languages = wp_get_available_translations() ) ) { + if ( wp_can_install_language_pack() && empty( $langugage ) && ( $languages = wp_get_available_translations() ) ) { display_header( 'language-chooser' ); echo '
'; wp_install_language_form( $languages ); diff --git a/wp-admin/setup-config.php b/wp-admin/setup-config.php index 1f97be4302..750b8b779a 100644 --- a/wp-admin/setup-config.php +++ b/wp-admin/setup-config.php @@ -93,7 +93,7 @@ if ( ! empty( $_REQUEST['language'] ) ) { } switch($step) { case -1: - if ( empty( $language ) && ( $languages = wp_get_available_translations() ) ) { + if ( wp_can_install_language_pack() && empty( $language ) && ( $languages = wp_get_available_translations() ) ) { setup_config_display_header( 'language-chooser' ); echo ''; wp_install_language_form( $languages );