Yaron Koren has submitted this change and it was merged.
Change subject: New parser function, #display_external_table, created by Dan
Bolser
......................................................................
New parser function, #display_external_table, created by Dan Bolser
Change-Id: I8384b39a7c9f381456fb590b14b978e6ed6bda12
---
M ED_ParserFunctions.php
M ExternalData.i18n.magic.php
M ExternalData.php
M README
4 files changed, 57 insertions(+), 3 deletions(-)
Approvals:
Yaron Koren: Verified; Looks good to me, approved
diff --git a/ED_ParserFunctions.php b/ED_ParserFunctions.php
index 610ddc5..7975598 100644
--- a/ED_ParserFunctions.php
+++ b/ED_ParserFunctions.php
@@ -333,6 +333,54 @@
}
return $text;
}
+
+
+ /**
+ * Render the #display_external_table parser function
+ *
+ * @author Dan Bolser
+ */
+ static function doDisplayExternalTable( &$parser ) {
+ global $edgValues;
+
+ $params = func_get_args();
+ array_shift( $params ); // we already know the $parser ...
+ $args = EDUtils::parseParams( $params ); // parse params into
name-value pairs
+
+ if ( array_key_exists( 'template', $args ) ) {
+ $template = $args['template'];
+ } else {
+ return "No template specified";
+ }
+
+ if ( array_key_exists( 'data', $args ) ) {
+ // parse the 'data' arg into mappings
+ $mappings = EDUtils::paramToArray( $args['data'],
false, true );
+ } else {
+ // or just use keys from edgValues
+ foreach ( $edgValues as $local_variable => $values ) {
+ $mappings[$local_variable] = $local_variable;
+ }
+ }
+
+ $num_loops = 0; // May differ when multiple '#get_'s are used
in one page
+ foreach ( $mappings as $template_param => $local_variable ) {
+ $num_loops = max( $num_loops, count(
$edgValues[$local_variable] ) );
+ }
+
+ $text = "";
+ for ( $i = 0; $i < $num_loops; $i++ ) {
+ $text .= '{{' . $template;
+ foreach ( $mappings as $template_param =>
$local_variable ) {
+ $value = self::getIndexedValue(
$local_variable, $i );
+ $text .= "|$template_param=$value";
+ }
+ $text .= "}}\n";
+ }
+
+ // This actually 'calls' the template that we built above
+ return array( $text, 'noparse' => false );
+ }
/**
* Render the #store_external_table parser function
diff --git a/ExternalData.i18n.magic.php b/ExternalData.i18n.magic.php
index f146f15..e7f10b8 100644
--- a/ExternalData.i18n.magic.php
+++ b/ExternalData.i18n.magic.php
@@ -13,6 +13,7 @@
'get_db_data' => array( 0, 'get_db_data' ),
'external_value' => array( 0, 'external_value' ),
'for_external_table' => array( 0, 'for_external_table' ),
+ 'display_external_table' => array( 0, 'display_external_table' ),
'store_external_table' => array( 0, 'store_external_table' ),
'clear_external_data' => array( 0, 'clear_external_data' ),
);
@@ -178,4 +179,4 @@
'external_value' => array( 0, 'зовнішнє_значення' ),
'for_external_table' => array( 0, 'для_зовнішньої_таблиці' ),
'store_external_table' => array( 0, 'зовнішня_таблиця_зберігання' ),
-);
\ No newline at end of file
+);
diff --git a/ExternalData.php b/ExternalData.php
index 9691a28..f886bdb 100644
--- a/ExternalData.php
+++ b/ExternalData.php
@@ -53,6 +53,7 @@
$parser->setFunctionHook( 'get_db_data', array( 'EDParserFunctions',
'doGetDBData' ) );
$parser->setFunctionHook( 'external_value', array( 'EDParserFunctions',
'doExternalValue' ) );
$parser->setFunctionHook( 'for_external_table', array(
'EDParserFunctions', 'doForExternalTable' ) );
+ $parser->setFunctionHook( 'display_external_table', array(
'EDParserFunctions', 'doDisplayExternalTable' ) );
$parser->setFunctionHook( 'store_external_table', array(
'EDParserFunctions', 'doStoreExternalTable' ) );
$parser->setFunctionHook( 'clear_external_data', array(
'EDParserFunctions', 'doClearExternalData' ) );
diff --git a/README b/README
index 0dd6607..2876809 100644
--- a/README
+++ b/README
@@ -1,6 +1,6 @@
External Data extension
- Version 1.5
+ Version 1.6
Yaron Koren, Michael Dale and David Macdonald
This is free software licensed under the GNU General Public License. Please
@@ -15,7 +15,8 @@
The extension defines eight parser functions: #get_web_data,
#get_external_data, #get_db_data, #get_ldap_data, #external_value,
-#for_external_table, #store_external_table and #clear_external_data.
+#for_external_table, #display_external_table, #store_external_table and
+#clear_external_data.
They are described below:
* #get_web_data retrieves the data from a URL that holds CSV, GFF,
@@ -36,6 +37,9 @@
* #for_external_table applies processing onto multiple rows retrieved by
any of the #get_*_data functions
+* #display_external_table is like #for_external_table, but passes the
+values of each row to a template, which handles the formatting.
+
* #store_external_table mimics a call to the Semantic Internal Objects
extension's #set_internal parser function onto each row retrieved by
any of the #get_*_data functions, in order to store the entire array
--
To view, visit https://gerrit.wikimedia.org/r/52084
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8384b39a7c9f381456fb590b14b978e6ed6bda12
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ExternalData
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <[email protected]>
Gerrit-Reviewer: Yaron Koren <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits