Mholloway has uploaded a new change for review.

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

Change subject: Add exit titles and warnings to API message response
......................................................................

Add exit titles and warnings to API message response

Needed for consumption by the mobile apps, which are currently
displaying generic messages.

Bug: T119126
Bug: T119128
Change-Id: Ib93786f35a3f27ec18e974cf032e9265f7bf75e1
---
M i18n/en.json
M i18n/qqq.json
M includes/ApiZeroBanner.php
3 files changed, 34 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroBanner 
refs/changes/59/264859/1

diff --git a/i18n/en.json b/i18n/en.json
index 6f7ce3d..f70139d 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -57,6 +57,7 @@
        "apihelp-zeroconfig-description": "Get configuration of the Zero 
extension.",
        "apihelp-zeroconfig-param-type": "What kind of Zero info is 
needed:\n;config:Get a trimmed-down carrier configuration based on the X-CS 
header.\n;message:Get language-appropriate verbiage based on X-CS header; 
requires agent param.",
        "apihelp-zeroconfig-param-agent": "When setting type to message, 
include a source agent value as well.",
+       "apihelp-zeroconfig-param-lang": "(Optional) Target language for custom 
partner info and exit warning messages.  If omitted, defaults to the wiki 
language.",
        "apihelp-zeroconfig-example-1": "Get configuration",
        "apihelp-zeroconfig-example-2": "Get verbiage for \"neat-app\""
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 61336a3..b2fd93d 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -74,6 +74,7 @@
        "apihelp-zeroconfig-description": 
"{{doc-apihelp-description|zeroconfig}}",
        "apihelp-zeroconfig-param-type": 
"{{doc-apihelp-param|zeroconfig|type}}",
        "apihelp-zeroconfig-param-agent": 
"{{doc-apihelp-param|zeroconfig|agent}}",
+       "apihelp-zeroconfig-param-lang": 
"{{doc-apihelp-param|zeroconfig|lang}}",
        "apihelp-zeroconfig-example-1": "{{doc-apihelp-example|zeroconfig}}",
        "apihelp-zeroconfig-example-2": "{{doc-apihelp-example|zeroconfig}}"
 }
diff --git a/includes/ApiZeroBanner.php b/includes/ApiZeroBanner.php
index fa67329..3040b9e 100644
--- a/includes/ApiZeroBanner.php
+++ b/includes/ApiZeroBanner.php
@@ -5,6 +5,7 @@
 use ApiBase;
 use ApiFormatBase;
 use ApiResult;
+use Language;
 
 /**
  * Utility class to avoid any warnings or any other additions by the API 
framework
@@ -86,12 +87,39 @@
                                $state = PageRenderingHooks::getState( $this );
                                $config = $state->getZeroConfig();
                                if ( $config && !$config->disableApps() && 
$config->showImages() ) {
+                                       if ( isset ( $params['lang'] ) && 
strlen( $params['lang'] ) ) {
+                                               $langCode = $params['lang'];
+                                       } else {
+                                               $langCode = 
$state->getLanguage()->getCode();
+                                       }
+                                       $lang = Language::factory( $langCode );
+
                                        // @fixme: we should pass in the 
$isFilePage
-                                       $text = $state->getBannerText( $config 
);
+                                       $text = $state->getBannerText( $config, 
false, $langCode );
                                        if ( $text ) {
                                                $result->addValue( $moduleName, 
'message', $text );
                                                $result->addValue( $moduleName, 
'background', $config->background() );
                                                $result->addValue( $moduleName, 
'foreground', $config->foreground() );
+                                       }
+
+                                       $exitTitle = 
$state::pickLocalizedString( $config->exitTitles(), $lang );
+                                       if ( $exitTitle ) {
+                                               $result->addValue( $moduleName, 
'exitTitle', $exitTitle );
+                                       }
+
+                                       $exitWarning = 
$state::pickLocalizedString( $config->exitWarnings(), $lang );
+                                       if ( $exitWarning ) {
+                                               $result->addValue( $moduleName, 
'exitWarning', $exitWarning );
+                                       }
+
+                                       $partnerInfoText = 
$state::pickLocalizedString( $config->partnerInfoText(), $lang );
+                                       if ( $partnerInfoText ) {
+                                               $result->addValue( $moduleName, 
'partnerInfoText', $partnerInfoText );
+                                       }
+
+                                       $partnerInfoUrl = 
$config->partnerInfoUrl();
+                                       if ( $partnerInfoUrl ) {
+                                               $result->addValue( $moduleName, 
'partnerInfoUrl', $partnerInfoUrl );
                                        }
                                }
                                // else json_encode will ultimately return as 
an empty array
@@ -116,6 +144,9 @@
                        'agent' => array(
                                ApiBase::PARAM_DFLT => '',
                        ),
+                       'lang' => array(
+                               ApiBase::PARAM_DFLT => '',
+                       ),
                );
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib93786f35a3f27ec18e974cf032e9265f7bf75e1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ZeroBanner
Gerrit-Branch: master
Gerrit-Owner: Mholloway <[email protected]>

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

Reply via email to