Yaron Koren has uploaded a new change for review. https://gerrit.wikimedia.org/r/143300
Change subject: Added new parser function, #get_soap_data ...................................................................... Added new parser function, #get_soap_data Change-Id: Ife729e63b68c3fad19e8e192b00d54c5ea6fe1c6 --- M ED_ParserFunctions.php M ED_Utils.php M ExternalData.i18n.magic.php M ExternalData.php M README 5 files changed, 96 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ExternalData refs/changes/00/143300/1 diff --git a/ED_ParserFunctions.php b/ED_ParserFunctions.php index 553ac54..63f4ad8 100644 --- a/ED_ParserFunctions.php +++ b/ED_ParserFunctions.php @@ -139,6 +139,68 @@ } /** + * Render the #get_soap_data parser function. + */ + static function doGetSOAPData( &$parser ) { + global $edgCurPageName, $edgValues, $edgCacheExpireTime; + + // If we're handling multiple pages, reset $edgValues + // when we move from one page to another. + $cur_page_name = $parser->getTitle()->getText(); + if ( ! isset( $edgCurPageName ) || $edgCurPageName != $cur_page_name ) { + $edgValues = array(); + $edgCurPageName = $cur_page_name; + } + + $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( 'url', $args ) ) { + $url = $args['url']; + } else { + return wfMessage( 'externaldata-no-param-specified', 'url')->parse(); + } + $url = str_replace( ' ', '%20', $url ); // do some minor URL-encoding + // if the URL isn't allowed (based on a whitelist), exit + if ( ! EDUtils::isURLAllowed( $url ) ) { + return "URL is not allowed"; + } + + if ( array_key_exists( 'request', $args ) ) { + $requestName = $args['request']; + } else { + return wfMessage( 'externaldata-no-param-specified', 'request')->parse(); + } + + if ( array_key_exists( 'requestData', $args ) ) { + $requestData = EDUtils::paramToArray( $args['requestData'] ); + } else { + return wfMessage( 'externaldata-no-param-specified', 'requestData')->parse(); + } + + if ( array_key_exists( 'response', $args ) ) { + $responseName = $args['response']; + } else { + return wfMessage( 'externaldata-no-param-specified', 'response')->parse(); + } + + if ( array_key_exists( 'data', $args ) ) { + $mappings = EDUtils::paramToArray( $args['data'] ); // parse the data arg into mappings + } else { + return wfMessage( 'externaldata-no-param-specified', 'data')->parse(); + } + + $external_values = EDUtils::getSOAPData( $url, $requestName, $requestData, $responseName, $mappings); + if ( is_string( $external_values ) ) { + // It's an error message - just display it on the + // screen. + return $external_values; + } + + self::setGlobalValuesArray( $external_values, array(), $mappings ); + } + + /** * Render the #get_ldap_data parser function */ static function doGetLDAPData( &$parser ) { diff --git a/ED_Utils.php b/ED_Utils.php index dce2fa2..5835ae2 100644 --- a/ED_Utils.php +++ b/ED_Utils.php @@ -908,4 +908,30 @@ return array(); } + static public function getSOAPData( $url, $requestName, $requestData, $responseName, $mappings) { + $client = new SoapClient($url); + try { + $result = $client->$requestName($requestData); + } catch (Exception $e) { + return "Caught exception: " . $e->getMessage(); + } + + $realResultJSON = $result->$responseName; + if ( $realResultJSON == '' ) { + return 'Error: no data found for this set of "requestData" fields.'; + } + + $realResult = json_decode( $realResultJSON ); + $errorKey = '#Error:'; + if ( array_key_exists( $errorKey, $realResult ) ) { + return 'Error: ' . $realResult->$errorKey; + } + + $values = array(); + foreach ( $mappings as $fieldName ) { + $values[$fieldName] = $realResult->$fieldName; + } + return $values; + } + } diff --git a/ExternalData.i18n.magic.php b/ExternalData.i18n.magic.php index 82a99d9..4ac7275 100644 --- a/ExternalData.i18n.magic.php +++ b/ExternalData.i18n.magic.php @@ -8,6 +8,7 @@ /** English (English) */ $magicWords['en'] = array( 'get_web_data' => array( 0, 'get_web_data' ), + 'get_soap_data' => array( 0, 'get_soap_data' ), 'get_ldap_data' => array( 0, 'get_ldap_data' ), 'get_db_data' => array( 0, 'get_db_data' ), 'external_value' => array( 0, 'external_value' ), @@ -199,4 +200,4 @@ 'display_external_table' => array( 0, '显示外部表单' ), 'store_external_table' => array( 0, '存储外部表单' ), 'clear_external_data' => array( 0, '清空外部数据' ), -); \ No newline at end of file +); diff --git a/ExternalData.php b/ExternalData.php index 92c14e3..d3008f7 100644 --- a/ExternalData.php +++ b/ExternalData.php @@ -12,7 +12,7 @@ $wgExtensionCredits['parserhook'][] = array( 'path' => __FILE__, 'name' => 'External Data', - 'version' => '1.7.0', + 'version' => '1.7-alpha', 'author' => array( 'Yaron Koren', 'Michael Dale', 'David Macdonald' ), 'url' => 'https://www.mediawiki.org/wiki/Extension:External_Data', 'descriptionmsg' => 'externaldata-desc', @@ -50,6 +50,7 @@ function edgRegisterParser( &$parser ) { $parser->setFunctionHook( 'get_web_data', array( 'EDParserFunctions', 'doGetWebData' ) ); + $parser->setFunctionHook( 'get_soap_data', array( 'EDParserFunctions', 'doGetSOAPData' ) ); $parser->setFunctionHook( 'get_ldap_data', array( 'EDParserFunctions', 'doGetLDAPData' ) ); $parser->setFunctionHook( 'get_db_data', array( 'EDParserFunctions', 'doGetDBData' ) ); $parser->setFunctionHook( 'external_value', array( 'EDParserFunctions', 'doExternalValue' ) ); diff --git a/README b/README index f40be03..8149f6d 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ External Data extension - Version 1.6.4 + Version 1.7-alpha Yaron Koren, Michael Dale and David Macdonald This is free software licensed under the GNU General Public License. Please @@ -13,7 +13,7 @@ from various sources: external URLs and local wiki pages (in CSV, GFF, JSON and XML formats), database tables, and LDAP servers. -The extension defines seven parser functions: #get_web_data, +The extension defines seven parser functions: #get_web_data, #get_soap_data, #get_db_data, #get_ldap_data, #external_value, #for_external_table, #display_external_table, #store_external_table and #clear_external_data. They are described below: @@ -21,6 +21,8 @@ * #get_web_data retrieves the data from a URL that holds CSV, GFF, JSON or XML, and assigns it to local variables or arrays. +* #get_soap_data retrieves data from a URL via SOAP. + * #get_db_data retrieves data from a database, using (in most cases) SQL-like syntax, and assigns it to local variables or arrays. -- To view, visit https://gerrit.wikimedia.org/r/143300 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ife729e63b68c3fad19e8e192b00d54c5ea6fe1c6 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ExternalData Gerrit-Branch: master Gerrit-Owner: Yaron Koren <yaro...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits