Yaron Koren has submitted this change and it was merged.

Change subject: Bad XML now leads to graceful exit
......................................................................


Bad XML now leads to graceful exit

Change-Id: Ibb1efc491978f47c8a9b69efc6929d4076a51628
---
M PageSchemas.classes.php
1 file changed, 51 insertions(+), 41 deletions(-)

Approvals:
  Yaron Koren: Checked; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/PageSchemas.classes.php b/PageSchemas.classes.php
index 1818a8e..8f86df5 100644
--- a/PageSchemas.classes.php
+++ b/PageSchemas.classes.php
@@ -317,51 +317,61 @@
                $row = $dbr->fetchRow( $res );
                if ( $row == null) {
                        $this->mIsPSDefined = false;
-               } else {
-                       // retrieve the third attribute, which is pp_value
-                       $pageXMLstr = $row[2];
-                       $this->mPageXML = simplexml_load_string ( $pageXMLstr );
-                       // index for template objects
-                       $templateCount = 0;
-                       $pageSectionCount = 0;
-                       $inherited_templates = array();
-                       foreach ( $this->mPageXML->children() as $tag => $child 
) {
-                               if ( $tag == 'InheritsFrom ' ) {
-                                       $schema_to_inherit = (string) 
$child->attributes()->schema;
-                                       if( $schema_to_inherit != null ) {
-                                               $inheritedSchemaObj = new 
PSSchema( $schema_to_inherit );
-                                               $inherited_templates = 
$inheritedSchemaObj->getTemplates();
-                                       }
+                       return;
+               }
+
+               // Retrieve the third attribute, which is pp_value.
+               $pageXMLstr = $row[2];
+
+               // Parse the string - if the parsing fails, just exit
+               // without displaying an error message; the parsing error
+               // messages aren't that helpful anyway.
+               $this->mPageXML = simplexml_load_string( $pageXMLstr, 
'SimpleXMLElement', LIBXML_NOERROR );
+               if ( $this->mPageXML == null ) {
+                       $this->mIsPSDefined = false;
+                       return;
+               }
+
+               // Index for template objects
+               $templateCount = 0;
+               $pageSectionCount = 0;
+               $inherited_templates = array();
+               foreach ( $this->mPageXML->children() as $tag => $child ) {
+                       if ( $tag == 'InheritsFrom ' ) {
+                               $schema_to_inherit = (string) 
$child->attributes()->schema;
+                               if( $schema_to_inherit != null ) {
+                                       $inheritedSchemaObj = new PSSchema( 
$schema_to_inherit );
+                                       $inherited_templates = 
$inheritedSchemaObj->getTemplates();
                                }
-                               if ( $tag == 'Template' ) {
-                                       $ignore = (string) 
$child->attributes()->ignore;
-                                       if ( count( $child->children() ) > 0 ) {
-                                               $templateObj = new PSTemplate( 
$child );
-                                               $this->mFormItemsList[] = 
array( 'type' => $tag,
-                                                       'number' => 
$templateCount,
-                                                       'item' => $templateObj 
);
-                                                       
$this->mTemplates[$templateCount]= $templateObj;
-                                               $templateCount++;
-                                       } elseif ( $ignore != "true" ) {
-                                               // Code to add templates from 
inherited templates
-                                               $temp_name = (string) 
$child->attributes()->name;
-                                               foreach( $inherited_templates 
as $inherited_template ) {
-                                                       if( 
$inherited_template['type'] == $tag && $temp_name == 
$inherited_template['item']->getName() ) {
-                                                               
$this->mFormItemsList[] = array( 'type' => $tag,
-                                                                       
'number' => $templateCount,
-                                                                       'item' 
=> $inherited_template );
-                                                                       
$this->mTemplates[$templateCount] = $inherited_template;
-                                                               
$templateCount++;
-                                                       }
+                       }
+                       if ( $tag == 'Template' ) {
+                               $ignore = (string) $child->attributes()->ignore;
+                               if ( count( $child->children() ) > 0 ) {
+                                       $templateObj = new PSTemplate( $child );
+                                       $this->mFormItemsList[] = array( 'type' 
=> $tag,
+                                               'number' => $templateCount,
+                                               'item' => $templateObj );
+                                               
$this->mTemplates[$templateCount]= $templateObj;
+                                       $templateCount++;
+                               } elseif ( $ignore != "true" ) {
+                                       // Code to add templates from inherited 
templates
+                                       $temp_name = (string) 
$child->attributes()->name;
+                                       foreach( $inherited_templates as 
$inherited_template ) {
+                                               if( $inherited_template['type'] 
== $tag && $temp_name == $inherited_template['item']->getName() ) {
+                                                       $this->mFormItemsList[] 
= array( 'type' => $tag,
+                                                               'number' => 
$templateCount,
+                                                               'item' => 
$inherited_template );
+                                                               
$this->mTemplates[$templateCount] = $inherited_template;
+                                                       $templateCount++;
                                                }
                                        }
-                               } elseif ( $tag == 'Section' ) {
-                                       $pageSectionObj = new PSPageSection( 
$child );
-                                       $this->mFormItemsList[] = array( 'type' 
=> $tag,
-                                                       'number' => 
$pageSectionCount,
-                                                       'item' => 
$pageSectionObj );
-                                       $pageSectionCount++;
                                }
+                       } elseif ( $tag == 'Section' ) {
+                               $pageSectionObj = new PSPageSection( $child );
+                               $this->mFormItemsList[] = array( 'type' => $tag,
+                                       'number' => $pageSectionCount,
+                                       'item' => $pageSectionObj );
+                               $pageSectionCount++;
                        }
                }
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/256688
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ibb1efc491978f47c8a9b69efc6929d4076a51628
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageSchemas
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <[email protected]>
Gerrit-Reviewer: Yaron Koren <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to