r45746 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45745‎ | r45746 | r45747 >
Date:20:12, 14 January 2009
Author:yaron
Status:deferred
Tags:
Comment:
Some XML and JSON improvements
Modified paths:
  • /trunk/extensions/ExternalData/ED_ParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ExternalData/ED_ParserFunctions.php
@@ -34,8 +34,8 @@
3535 $edgXMLValues = array();
3636
3737 $xml_parser = xml_parser_create();
38 - xml_set_element_handler( $xml_parser, "EDParserFunctions::startElement", "EDParserFunctions::endElement" );
39 - xml_set_character_data_handler( $xml_parser, "EDParserFunctions::getContent" );
 38+ xml_set_element_handler( $xml_parser, array( 'EDParserFunctions', 'startElement' ), array( 'EDParserFunctions', 'endElement' ) );
 39+ xml_set_character_data_handler( $xml_parser, array( 'EDParserFunctions', 'getContent' ) );
4040 if (!xml_parse($xml_parser, $xml, true)) {
4141 echo(sprintf("XML error: %s at line %d",
4242 xml_error_string(xml_get_error_code($xml_parser)),
@@ -63,7 +63,7 @@
6464 static function parseTree( $tree, &$retrieved_values ) {
6565 foreach ($tree as $key => $val) {
6666 if (is_array( $val )) {
67 - self::parseTree( $val, &$retrieved_values );
 67+ self::parseTree( $val, $retrieved_values );
6868 } else {
6969 $retrieved_values[$key] = $val;
7070 }
@@ -71,10 +71,15 @@
7272 }
7373
7474 static function getJSONData( $json ) {
 75+ // escape if json_decode() isn't supported
 76+ if ( ! function_exists( 'json_decode' ) ) {
 77+ echo( "Error: json_decode() is not supported in this version of PHP" );
 78+ return array();
 79+ }
7580 $json_tree = json_decode($json, true);
7681 $values = array();
7782 if ( is_array( $json_tree ) ) {
78 - self::parseTree( $json_tree, &$values );
 83+ self::parseTree( $json_tree, $values );
7984 }
8085 return $values;
8186 }

Status & tagging log