jenkins-bot has submitted this change and it was merged.

Change subject: API output should give parsed config, not raw config
......................................................................


API output should give parsed config, not raw config

Change-Id: I581881fb344b295fc4c9749bec306edf95c5c63b
---
M includes/ApiQueryAllCampaigns.php
M includes/UploadWizardCampaign.php
2 files changed, 67 insertions(+), 1 deletion(-)

Approvals:
  Brion VIBBER: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/ApiQueryAllCampaigns.php 
b/includes/ApiQueryAllCampaigns.php
index 35a8027..e63418f 100644
--- a/includes/ApiQueryAllCampaigns.php
+++ b/includes/ApiQueryAllCampaigns.php
@@ -70,7 +70,7 @@
                        $result->addValue(
                                array( 'query', $this->getModuleName(), 
$row->campaign_id ),
                                '*',
-                               json_encode( $campaign->getConfig() )
+                               json_encode( $campaign->getParsedConfig() )
                        );
                        $result->addValue(
                                array( 'query', $this->getModuleName(), 
$row->campaign_id ),
diff --git a/includes/UploadWizardCampaign.php 
b/includes/UploadWizardCampaign.php
index b6df404..4be798a 100644
--- a/includes/UploadWizardCampaign.php
+++ b/includes/UploadWizardCampaign.php
@@ -28,6 +28,15 @@
        protected $config = array();
 
        /**
+        * The campaign configuration, after wikitext properties have been 
parsed.
+        *
+        * @since 1.2
+        * @var array
+        */
+       protected $parsedConfig = null;
+
+
+       /**
         * The WikiPage representing the current campaign
         *
         * @since 1.4
@@ -84,4 +93,61 @@
        public function getConfig() {
                return $this->config;
        }
+
+       /**
+        * Parses the values in an assoc array as wikitext
+        *
+        * @param $array Array
+        * @param $forKeys Array: Array of keys whose values should be parsed
+        *
+        * @since 1.3
+        *
+        * @return array
+        */
+       private function parseArrayValues( $array, $forKeys = null ) {
+               // FIXME: Don't abuse RequestContext like this
+               // Use the parser directly
+               $out = RequestContext::getMain()->getOutput();
+               $parsed = array();
+               foreach ( $array as $key => $value ) {
+                       if ( $forKeys === null || in_array( $key, $forKeys ) ) {
+                               $parsed[$key] = $out->parseInline( $value );
+                       }
+               }
+               return $parsed;
+       }
+
+       /**
+        * Returns all config parameters, after parsing the wikitext based ones
+        *
+        * @since 1.3
+        *
+        * @return array
+        */
+       public function getParsedConfig() {
+               if ( $this->parsedConfig === null ) {
+                       $parsedConfig = array();
+                       foreach ( $this->config as $key => $value ) {
+                               switch ( $key ) {
+                               case "display":
+                                       $parsedConfig['display'] = 
$this->parseArrayValues( $value );
+                                       break;
+                               case "fields":
+                                       $parsedConfig['fields'] = array();
+                                       foreach ( $value as $field ) {
+                                               $parsedConfig['fields'][] = 
$this->parseArrayValues(
+                                                       $field,
+                                                       array( 'label' )
+                                               );
+                                       }
+                                       break;
+                               default:
+                                       $parsedConfig[$key] = $value;
+                                       break;
+                               }
+                       }
+                       $this->parsedConfig = $parsedConfig;
+               }
+               return $this->parsedConfig;
+       }
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I581881fb344b295fc4c9749bec306edf95c5c63b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Yuvipanda <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to