Yuvipanda has uploaded a new change for review.
https://gerrit.wikimedia.org/r/81155
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(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard
refs/changes/55/81155/1
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: newchange
Gerrit-Change-Id: I581881fb344b295fc4c9749bec306edf95c5c63b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Yuvipanda <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits