diff --git a/wp-admin/ms-edit.php b/wp-admin/ms-edit.php index 8cab8aaa7d..395bf71a31 100644 --- a/wp-admin/ms-edit.php +++ b/wp-admin/ms-edit.php @@ -23,7 +23,7 @@ switch ( $_GET['action'] ) { if ( empty( $_POST ) ) wp_die( __("You probably need to go back to the options page") ); - if ( isset($_POST['WPLANG']) ) + if ( isset($_POST['WPLANG']) && ( '' === $_POST['WPLANG'] || in_array($_POST['WPLANG'], get_available_languages()) ) ) update_site_option( "WPLANG", $_POST['WPLANG'] ); if ( is_email( $_POST['admin_email'] ) ) diff --git a/wp-admin/ms-options.php b/wp-admin/ms-options.php index 2bc3efc356..df4c176054 100644 --- a/wp-admin/ms-options.php +++ b/wp-admin/ms-options.php @@ -252,19 +252,15 @@ if (isset($_GET['updated'])) {

(These settings may be overridden by blog owners)') ?>

diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index efb9ad5ac6..a7c0a755a3 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -484,4 +484,30 @@ function &get_translations_for_domain( $domain ) { function translate_user_role( $name ) { return translate_with_gettext_context( before_last_bar($name), 'User role' ); } + +/** + * Get all available languages based on the presence of *.mo files in a given directory. The default directory is WP_LANG_DIR. + * + * @since 3.0.0 + * + * @param string $dir A directory in which to search for language files. The default directory is WP_LANG_DIR. + * @return array Array of language codes or an empty array if no languages are present. Language codes are formed by stripping the .mo extension from the language file names. + */ +function get_available_languages( $dir = null ) { + $languages = array(); + + if ( empty($dir) ) + $dir = WP_LANG_DIR; + + if ( is_dir( $dir ) && $dh = opendir( $dir ) ) { + while ( ( $lang_file = readdir( $dh ) ) !== false ) { + if ( substr( $lang_file, -3 ) == '.mo' ) + $languages[] = basename($lang_file, '.mo'); + } + closedir($dh); + } + + return $languages; +} + ?>