Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/189920
Change subject: Add fail-safe check to Utils::getLanguageCodes
......................................................................
Add fail-safe check to Utils::getLanguageCodes
Core's Language::fetchLanguageNames() probably never returns an empty
array, but who knows? Very odd, very hard to track things happen in
Wikibase if this is ever the case. So better add this check and throw
an exception as early as possible.
This is the result of a discussion I had with Daniel: What to do if a
list of "allowed codes" is empty?
1. Empty array means the same as null: No filter, allow everything
(my favorite, but not an option for Daniel).
2. Allow nothing (Daniel's favorite, but not an option in my opinion).
3. Neither nor (this patch).
This is split from Ic506adc.
Change-Id: I3507a4604960588faa3932fe43d9c2509ae27650
---
M lib/includes/Utils.php
1 file changed, 8 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/20/189920/1
diff --git a/lib/includes/Utils.php b/lib/includes/Utils.php
index dfada5e..87d5c2c 100644
--- a/lib/includes/Utils.php
+++ b/lib/includes/Utils.php
@@ -3,6 +3,7 @@
namespace Wikibase;
use Language;
+use MWException;
/**
* Utility functions for Wikibase.
@@ -23,13 +24,18 @@
*
* @since 0.1
*
- * @return array
+ * @throws MWException if the list can not be obtained.
+ * @return string[]
*/
public static function getLanguageCodes() {
static $languageCodes = null;
- if ( is_null( $languageCodes ) ) {
+ if ( $languageCodes === null ) {
$languageCodes = array_keys(
Language::fetchLanguageNames() );
+
+ if ( empty( $languageCodes ) ) {
+ throw new MWException( 'List of language names
is empty' );
+ }
}
return $languageCodes;
--
To view, visit https://gerrit.wikimedia.org/r/189920
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3507a4604960588faa3932fe43d9c2509ae27650
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits