Index: trunk/extensions/TemplateInfo/TemplateInfo.hooks.php |
— | — | @@ -19,6 +19,39 @@ |
20 | 20 | return true; |
21 | 21 | } |
22 | 22 | |
| 23 | + public static function validateXML( $xml ) { |
| 24 | + $xmlDTD =<<<END |
| 25 | +<?xml version="1.0" encoding="utf-8"?> |
| 26 | +<!DOCTYPE template [ |
| 27 | +<!ELEMENT template (description?,params?,data*)> |
| 28 | +<!ELEMENT params (param|group)*> |
| 29 | +<!ELEMENT param (label?,description?,options?,type?,data*)> |
| 30 | +<!ATTLIST param id ID #REQUIRED> |
| 31 | +<!ELEMENT group (label?,description?,param*,data*)> |
| 32 | +<!ELEMENT label (#PCDATA|msg)*> |
| 33 | +<!ELEMENT description (#PCDATA|msg)*> |
| 34 | +<!ELEMENT options (option*)> |
| 35 | +<!ELEMENT option (#PCDATA|msg)*> |
| 36 | +<!ELEMENT type (field*)> |
| 37 | +<!ATTLIST type name CDATA #REQUIRED> |
| 38 | +<!ELEMENT field EMPTY> |
| 39 | +<!ATTLIST field name CDATA #REQUIRED> |
| 40 | +<!ATTLIST field value CDATA #REQUIRED> |
| 41 | +<!ELEMENT msg (#PCDATA)> |
| 42 | +<!ATTLIST msg lang CDATA #REQUIRED> |
| 43 | +<!ELEMENT data (field*)> |
| 44 | +<!ATTLIST data app CDATA #REQUIRED> |
| 45 | +]> |
| 46 | + |
| 47 | +END; |
| 48 | + // we are using the SimpleXML library to do the XML validation |
| 49 | + // for now - this may change later |
| 50 | + // hide parsing warnings |
| 51 | + libxml_use_internal_errors(true); |
| 52 | + $xml_success = simplexml_load_string($xmlDTD . $xml); |
| 53 | + return $xml_success; |
| 54 | + } |
| 55 | + |
23 | 56 | // Render the displayed XML, if any |
24 | 57 | public static function render( $input, $args, $parser, $frame ) { |
25 | 58 | // if this call is contained in a transcluded page or template, |
— | — | @@ -28,7 +61,10 @@ |
29 | 62 | |
30 | 63 | // Store XML in the page_props table |
31 | 64 | // TODO: Do processing here, like parse to an array |
32 | | - $parser->getOutput()->setProperty( 'templateinfo', $input ); |
| 65 | + if ( TemplateInfoHooks::validateXML( $input ) ) |
| 66 | + $parser->getOutput()->setProperty( 'templateinfo', $input ); |
| 67 | + else |
| 68 | + $parser->getOutput()->setProperty( 'templateinfo', "Error: Invalid XML" ); |
33 | 69 | |
34 | 70 | // Return output |
35 | 71 | $text = "<p>" . wfMsg( 'templateinfo-header' ) . "</p>\n"; |
Index: trunk/extensions/TemplateInfo/ApiQueryTemplateInfo.php |
— | — | @@ -20,39 +20,6 @@ |
21 | 21 | parent :: __construct( $query, $moduleName, 'ti' ); |
22 | 22 | } |
23 | 23 | |
24 | | - private function validateXML( $xml ) { |
25 | | - $xmlDTD =<<<END |
26 | | -<?xml version="1.0" encoding="utf-8"?> |
27 | | -<!DOCTYPE template [ |
28 | | -<!ELEMENT template (description?,params?,data*)> |
29 | | -<!ELEMENT params (param|group)*> |
30 | | -<!ELEMENT param (label?,description?,options?,type?,data*)> |
31 | | -<!ATTLIST param id ID #REQUIRED> |
32 | | -<!ELEMENT group (label?,description?,param*,data*)> |
33 | | -<!ELEMENT label (#PCDATA|msg)*> |
34 | | -<!ELEMENT description (#PCDATA|msg)*> |
35 | | -<!ELEMENT options (option*)> |
36 | | -<!ELEMENT option (#PCDATA|msg)*> |
37 | | -<!ELEMENT type (field*)> |
38 | | -<!ATTLIST type name CDATA #REQUIRED> |
39 | | -<!ELEMENT field EMPTY> |
40 | | -<!ATTLIST field name CDATA #REQUIRED> |
41 | | -<!ATTLIST field value CDATA #REQUIRED> |
42 | | -<!ELEMENT msg (#PCDATA)> |
43 | | -<!ATTLIST msg lang CDATA #REQUIRED> |
44 | | -<!ELEMENT data (field*)> |
45 | | -<!ATTLIST data app CDATA #REQUIRED> |
46 | | -]> |
47 | | - |
48 | | -END; |
49 | | - // we are using the SimpleXML library to do the XML validation |
50 | | - // for now - this may change later |
51 | | - // hide parsing warnings |
52 | | - libxml_use_internal_errors(true); |
53 | | - $xml_success = simplexml_load_string($xmlDTD . $xml); |
54 | | - return $xml_success; |
55 | | - } |
56 | | - |
57 | 24 | public function execute() { |
58 | 25 | $params = $this->extractRequestParams(); |
59 | 26 | $titles = $this->getPageSet()->getGoodTitles(); |
— | — | @@ -72,11 +39,7 @@ |
73 | 40 | $res = $this->select(__METHOD__); |
74 | 41 | while ( $row = $this->getDB()->fetchObject( $res ) ) { |
75 | 42 | $vals = array( ); |
76 | | - if ($this->validateXML( $row->pp_value )) { |
77 | | - ApiResult::setContent( $vals, $row->pp_value ); |
78 | | - } else { |
79 | | - ApiResult::setContent( $vals, "Error! Invalid XML" ); |
80 | | - } |
| 43 | + ApiResult::setContent( $vals, $row->pp_value ); |
81 | 44 | $fit = $this->addPageSubItems( $row->pp_page, $vals ); |
82 | 45 | if( !$fit ) { |
83 | 46 | $this->setContinueEnumParameter( 'continue', $row->pp_page ); |