Yurik has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/69631


Change subject: Zero config sorts & deduplicates showLangs & whitelisted
......................................................................

Zero config sorts & deduplicates showLangs & whitelisted

* showLangs parameter will be de-duplicated, while preserving order
* whitelistedLangs parameter will be de-duplicated and sorted in
the same order as showLangs, followed by alphabetically ordered
languages that are not in showLangs.

Change-Id: Id8b9221ed81cfdad70a6be837686a51242e690b9
---
M includes/CarrierConfig.php
1 file changed, 17 insertions(+), 4 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroRatedMobileAccess 
refs/changes/31/69631/1

diff --git a/includes/CarrierConfig.php b/includes/CarrierConfig.php
index 161b26c..7ae1f0b 100644
--- a/includes/CarrierConfig.php
+++ b/includes/CarrierConfig.php
@@ -210,20 +210,33 @@
                //'showLangs' => null,        // List of language codes to show 
on Zero page
                $this->check( 'showLangs', null,
                        function( $v ) {
-                               return CarrierConfig::isArray( $v, false )
+                               if ( CarrierConfig::isArray( $v, false )
                                        && CarrierConfig::isArrayOfLangs( $v )
                                        && count( $v ) > 0
-                                       ? null : wfMessage( 
'zeroconfig-show_langs' );
+                               ) {
+                                       // Remove duplicates while preserving 
original order
+                                       $v = array_unique( $v );
+                                       ksort( $v );
+                                       return $v;
+                               }
+                               return wfMessage( 'zeroconfig-show_langs' );
                        } );
 
                //'whitelistedLangs' => null, // List of language codes to show 
banner on, or empty list to allow on all languages
                $showLangs = $this->config['showLangs'];
                $this->check( 'whitelistedLangs', null,
                        function( $v ) use ( $showLangs ) {
-                               return CarrierConfig::isArray( $v, false )
+                               if ( CarrierConfig::isArray( $v, false )
                                        && CarrierConfig::isArrayOfLangs( $v )
                                        && ( count( $v ) === 0 || count( 
array_diff( $showLangs, $v ) ) === 0 )
-                                       ? null : wfMessage( 
'zeroconfig-whitelisted_langs' );
+                               ) {
+                                       // Make $v in the same order as 
$showLangs, followed by alphabetical leftovers
+                                       $v = array_unique( $v );
+                                       $leftovers = array_diff( $v, $showLangs 
);
+                                       sort( $leftovers );
+                                       return array_merge( $showLangs, 
$leftovers );
+                               }
+                               return wfMessage( 
'zeroconfig-whitelisted_langs' );
                        } );
 
                // Orange Congo wanted to be able to override the 'kg' language 
name to 'Kikongo'

-- 
To view, visit https://gerrit.wikimedia.org/r/69631
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id8b9221ed81cfdad70a6be837686a51242e690b9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to