jenkins-bot has submitted this change and it was merged.
Change subject: Show default and fallback values in zero config page
......................................................................
Show default and fallback values in zero config page
* Name & banner values show fallbacks values
* All values that are the same as default are highlighted in purple
* Sort 'sites' config value
Change-Id: Idea3f6d8e723cd0f7f975c5326b9420dcbca95c0
---
M includes/CarrierConfig.php
M includes/ZeroConfigContent.php
M modules/zero.config.css
3 files changed, 75 insertions(+), 18 deletions(-)
Approvals:
Dr0ptp4kt: Verified; Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/CarrierConfig.php b/includes/CarrierConfig.php
index b3ddf22..9cceda2 100644
--- a/includes/CarrierConfig.php
+++ b/includes/CarrierConfig.php
@@ -22,6 +22,7 @@
private $errors = array();
private $config = array();
private $defaultUsed = array();
+ private $sameAsDefault = array();
private $unknownFields;
private $thorough;
@@ -68,7 +69,7 @@
}
/**
- * Get an array of field that were not present in the configuration
+ * Get an array of fields that were not present in the configuration
* @return array
*/
public function getDefaultUsed() {
@@ -76,7 +77,15 @@
}
/**
- * Get a dictionary of all unrecognized field with their values
+ * Get an array of fields that have the same value as default
+ * @return array
+ */
+ public function getSameAsDefault() {
+ return $this->sameAsDefault;
+ }
+
+ /**
+ * Get a dictionary of all unrecognized fields with their values
* @return Array
*/
public function getUnknownFields() {
@@ -126,8 +135,8 @@
// Which sites are whitelisted. Default - both m & zero wiki
$this->check( 'sites',
array(
- 'zero.wikipedia',
'm.wikipedia',
+ 'zero.wikipedia',
),
function( $v ) {
if ( is_string( $v ) ) {
@@ -144,8 +153,8 @@
}
}
$validValues = array(
- 'zero.wikipedia',
'm.wikipedia',
+ 'zero.wikipedia',
);
if ( is_array( $v ) ) {
$v = array_map( 'strtolower', $v );
@@ -161,6 +170,7 @@
$v = false;
} else {
$v = array_unique( $v );
+ sort( $v );
}
}
if ( CarrierConfig::isArray( $v, false )
@@ -321,6 +331,9 @@
}
}
$this->config[$field] = $res;
+ if ( $res === $default ) {
+ $this->sameAsDefault[$field] = true;
+ }
}
private function getValue( $field ) {
diff --git a/includes/ZeroConfigContent.php b/includes/ZeroConfigContent.php
index 6081c4f..c6a1975 100644
--- a/includes/ZeroConfigContent.php
+++ b/includes/ZeroConfigContent.php
@@ -3,6 +3,7 @@
namespace Extensions\ZeroRatedMobileAccess;
use FormatJson;
+use Language;
use ParserOptions;
use ParserOutput;
use Title;
@@ -68,14 +69,16 @@
/**
* Constructs an HTML representation of a JSON object.
* @param Array $config
- * @param $isTop
+ * @param int $level Tree level
+ * @param string $parentKey The name of the parent key
+ * @param array $parentValues The values of the current container
* @return string: HTML.
*/
- private function objectTable( $config, $isTop = true ) {
+ private function objectTable( $config, $level = 0, $parentKey = null,
$parentValues = null ) {
wfProfileIn( __METHOD__ );
$rows = array();
- $tdAttributes = array( 'class' => 'value' );
+ $tdAttributes = array( 'class' => 'mw-zero-config-value' );
foreach ( $config as $key => $val ) {
if ( is_string( $key ) ) {
@@ -85,15 +88,15 @@
}
if ( is_array( $val ) ) {
if ( count( $val ) === 0 ) {
- if ( $isTop && $key ===
'whitelistedLangs' ) {
+ if ( $level === 0 && $key ===
'whitelistedLangs' ) {
$td = Xml::element( 'td',
$tdAttributes, wfMessage( 'zeroconfig-whitelisted_langs-all' ) );
} else {
$td = Xml::element( 'td',
$tdAttributes, '' );
}
- } elseif ( $isTop && ( $key === 'showLangs' ||
$key === 'whitelistedLangs' ) ) {
+ } elseif ( $level === 0 && ( $key ===
'showLangs' || $key === 'whitelistedLangs' ) ) {
$td = Xml::tags( 'td', $tdAttributes,
implode( ', ', $val ) );
} else {
- $td = Xml::tags( 'td', null,
$this->objectTable( $val, false ) );
+ $td = Xml::tags( 'td', null,
$this->objectTable( $val, $level + 1, $key, $val ) );
}
} else {
if ( !is_string( $val ) ) {
@@ -103,12 +106,44 @@
}
$attribs = null;
- if ( $isTop ) {
- if ( array_key_exists( $key,
$this->config->getDefaultUsed() ) ) {
- $attribs = array( 'class' =>
'mw-zero-config-default' );
- } elseif ( array_key_exists( $key,
$this->config->getUnknownFields() ) ) {
- $attribs = array( 'class' =>
'mw-zero-config-unknown' );
- }
+ switch ( $level ) {
+ case 0:
+ if ( array_key_exists( $key,
$this->config->getDefaultUsed() ) ) {
+ $attribs = array( 'class' =>
'mw-zero-config-default' );
+ } elseif ( array_key_exists( $key,
$this->config->getSameAsDefault() ) ) {
+ $attribs = array( 'class' =>
'mw-zero-config-same' );
+ } elseif ( array_key_exists( $key,
$this->config->getUnknownFields() ) ) {
+ $attribs = array( 'class' =>
'mw-zero-config-unknown' );
+ }
+ break;
+ case 1:
+ if ( $parentKey === 'name' ||
$parentKey === 'banner' ) {
+ $lang = Language::factory( $key
);
+ $fallbacks =
$lang->getFallbackLanguages();
+ if ( count( $fallbacks ) === 0
&& $key !== 'en' ) {
+ $fallbacks = array(
'en' );
+ }
+ if ( count( $fallbacks ) > 0 ) {
+ $fbElems = array();
+ foreach ( $fallbacks as
$fb ) {
+ $attr = null;
+ if (
array_key_exists( $fb, $parentValues ) ) {
+ if (
$parentValues[$fb] === $val ) {
+
$attr = array( 'class' => 'mw-zero-config-same' );
+ }
+ } else {
+ $attr =
array( 'class' => 'mw-zero-config-unknown' );
+ }
+ $fbElems[] =
Xml::element( 'span', $attr, $fb );
+ }
+ $td .= Xml::tags( 'td',
array( 'class' => 'mw-zero-config-info' ), '→ ' . implode( ' → ',
$fbElems ) );
+ }
+ } elseif ( $parentKey ===
'langNameOverrides' ) {
+ $langName =
Language::fetchLanguageName( $key );
+ $original = $langName === $val
? Xml::span( $langName, 'mw-zero-config-same' ) : htmlspecialchars( $langName );
+ $td .= Xml::tags( 'td', array(
'class' => 'mw-zero-config-info' ), $original );
+ }
+ break;
}
$rows[] = Xml::tags( 'tr', $attribs, $th . $td );
}
@@ -136,7 +171,7 @@
foreach ( $langs as $langCode => $_ ) {
$th = Xml::elementClean( 'th', null, $langCode );
// render the banner without hiding it
- $lang = \Language::factory( $langCode );
+ $lang = Language::factory( $langCode );
// Get localized "wikipedia" sitename. If null, will
use default {{SITENAME}}
$sitename = $wgConf->get( 'wgSitename', str_replace(
'-', '_', $langCode ) . 'wiki' );
$td = $td = Xml::tags( 'td', null,
diff --git a/modules/zero.config.css b/modules/zero.config.css
index 49c5c2b..767d3e4 100644
--- a/modules/zero.config.css
+++ b/modules/zero.config.css
@@ -24,9 +24,12 @@
font-style: italic;
}
-.mw-zero-config .value {
+.mw-zero-config .mw-zero-config-value {
background-color: #dcfae3;
font-family: 'Bitstream Vera Sans Mono', 'DejaVu Sans Mono', Monaco,
Courier, monospace;
+}
+
+.mw-zero-config-info {
}
.mw-zero-config tr {
@@ -42,8 +45,14 @@
opacity: 0.3;
}
+.mw-zero-config-same {
+ color: purple;
+ font-weight: bold;
+}
+
.mw-zero-config-unknown {
color: red;
+ font-weight: bold;
}
.mw-zero-config caption {
--
To view, visit https://gerrit.wikimedia.org/r/68819
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idea3f6d8e723cd0f7f975c5326b9420dcbca95c0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>
Gerrit-Reviewer: Dr0ptp4kt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits