Index: trunk/extensions/TemplateInfo/TemplateInfo.hooks.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | return true; |
21 | 21 | } |
22 | 22 | |
23 | | - public static function validateXML( $xml ) { |
| 23 | + public static function validateXML( $xml, &$error_msg ) { |
24 | 24 | $xmlDTD =<<<END |
25 | 25 | <?xml version="1.0" encoding="utf-8"?> |
26 | 26 | <!DOCTYPE template [ |
— | — | @@ -49,22 +49,27 @@ |
50 | 50 | // hide parsing warnings |
51 | 51 | libxml_use_internal_errors(true); |
52 | 52 | $xml_success = simplexml_load_string($xmlDTD . $xml); |
| 53 | + $errors = libxml_get_errors(); |
| 54 | + $message = $errors[0]->message; |
| 55 | + //$line = $errors[0]->line; |
| 56 | + $error_msg = "ERROR: $message"; |
53 | 57 | return $xml_success; |
54 | 58 | } |
55 | 59 | |
56 | 60 | // Render the displayed XML, if any |
57 | 61 | public static function render( $input, $args, $parser, $frame ) { |
58 | 62 | // if this call is contained in a transcluded page or template, |
59 | | - // or if the inpur is empty, display nothing |
| 63 | + // or if the input is empty, display nothing |
60 | 64 | if ( !$frame->title->equals( $parser->getTitle() ) || $input == '' ) |
61 | 65 | return; |
62 | 66 | |
63 | 67 | // Store XML in the page_props table |
64 | 68 | // TODO: Do processing here, like parse to an array |
65 | | - if ( TemplateInfoHooks::validateXML( $input ) ) |
| 69 | + $error_msg = null; |
| 70 | + if ( TemplateInfoHooks::validateXML( $input, $error_msg ) ) |
66 | 71 | $parser->getOutput()->setProperty( 'templateinfo', $input ); |
67 | 72 | else |
68 | | - $parser->getOutput()->setProperty( 'templateinfo', "Error: Invalid XML" ); |
| 73 | + $parser->getOutput()->setProperty( 'templateinfo', $error_msg ); |
69 | 74 | |
70 | 75 | // Return output |
71 | 76 | $text = "<p>" . wfMsg( 'templateinfo-header' ) . "</p>\n"; |