r92877 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92876‎ | r92877 | r92878 >
Date:19:03, 22 July 2011
Author:ankitgarg833
Status:deferred
Tags:
Comment:
added support for inheritance.
Modified paths:
  • /trunk/extensions/PageSchemas/PageSchemas.classes.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PageSchemas/PageSchemas.classes.php
@@ -8,7 +8,6 @@
99
1010 class PageSchemas {
1111
12 -
1312 /* Functions */
1413 //Copied from SFUtils
1514 public static function titleString( $title ) {
@@ -41,9 +40,11 @@
4241 <?xml version="1.0" encoding="utf-8"?>
4342 <!DOCTYPE PageSchema [
4443 <!ELEMENT PageSchema (Template*)>
 44+<!ELEMENT PageSchema (Form*)>
4545 <!ATTLIST PageSchema name CDATA #REQUIRED>
4646 <!ELEMENT Template (Field*)>
4747 <!ATTLIST Template name CDATA #REQUIRED>
 48+<!ATTLIST Form name CDATA #REQUIRED>
4849 <!ATTLIST Field name CDATA #REQUIRED>
4950 ]>
5051
@@ -88,7 +89,10 @@
8990 $name = $class_schema_xml->attributes()->name;
9091 $text .= self::tableRowHTML('paramGroup', 'PageSchema', $name);
9192 foreach ( $class_schema_xml->children() as $tag => $child ) {
92 - if ($tag == 'Template') {
 93+ if ( $tag == 'Form' ){
 94+ $text .= self::parseFormElem($child);
 95+ }
 96+ else if ($tag == 'Template') {
9397 $text .= self::parseTemplate($child);
9498 } else{
9599 echo "Code to be added by other extension\n";
@@ -100,6 +104,14 @@
101105 }
102106 return $text;
103107 }
 108+ static function parseFormElem( $form_xml ) {
 109+ $name = $form_xml->attributes()->name;
 110+ $text = self::tableRowHTML('param', 'Form', $name);
 111+ foreach ($form_xml->children() as $key => $value ) {
 112+ $text .= self::tableMessageRowHTML("paramAttrMsg", (string)$key, (string)$value );
 113+ }
 114+ return $text;
 115+ }
104116 static function parseTemplate ( $template_xml ) {
105117 $name = $template_xml->attributes()->name;
106118 $text = self::tableRowHTML('param', 'Template', $name);
@@ -129,6 +141,7 @@
130142 public $pageXmlstr= "";
131143 public $pageName="";
132144 public $formName="";
 145+ public $formArray = array();
133146 /* Stores the templte objects */
134147 public $PSTemplates = array();
135148
@@ -163,13 +176,13 @@
164177 $schema_to_inherit = (string) $child->attributes()->schema;
165178 if( $schema_to_inherit !=null ){
166179 $inheritedSchemaObj = new PSSchema( $schema_to_inherit );
167 - $inherited_templates = $inheritedSchemaObj->getTemplates();
 180+ $inherited_templates = $inheritedSchemaObj->getTemplates();
168181 }
169182 }
170183 if ( $tag == 'Template' ) {
171184 $ignore = (string) $child->attributes()->ignore;
172 - if( $child->children() != null ){
173 - $templateObj = new PSTemplate($child);
 185+ if( count($child->children()) > 1 ){
 186+ $templateObj = new PSTemplate($child);
174187 $this->PSTemplates[$i++]= $templateObj;
175188 }else if( $ignore != "true" ) {
176189 //Code to Add Templates from Inherited templates
@@ -181,8 +194,12 @@
182195 }
183196 }
184197 }
185 - if ( $tag == 'FormName' ) {
186 - $this->formName = (string)$child;
 198+ if ( $tag == 'Form' ) {
 199+ $this->formName = (string) $child->attributes()->name;
 200+ $this->formArray['name'] = (string) $child->attributes()->name;
 201+ foreach ($child->children() as $tag => $formelem) {
 202+ $this->formArray[(string)$tag] = (string)$formelem;
 203+ }
187204 }
188205 }
189206 }
@@ -191,6 +208,10 @@
192209 wfRunHooks( 'PageSchemasGeneratePages', array( $this, $toGenPageList ));
193210 }
194211 /*return an array of PSTemplate Objects */
 212+ function getFormArray () {
 213+ return $this->formArray;
 214+ }
 215+ /*return an array of PSTemplate Objects */
195216 function getTemplates () {
196217 return $this->PSTemplates;
197218 }
@@ -220,17 +241,17 @@
221242 }
222243 /*index for template objects */
223244 $i = 0 ;
224 - $inherited_fields = null ;
225 - foreach ($template_xml->children() as $child) {
226 - if ( $child->getName == 'InheritsFrom ' ) {
 245+ $inherited_fields = null ;
 246+ foreach ($template_xml->children() as $child) {
 247+ if ( $child->getName() == 'InheritsFrom' ) {
227248 $schema_to_inherit = (string) $child->attributes()->schema;
228 - $template_to_inherit = (string) $child->attributes()->template;
 249+ $template_to_inherit = (string) $child->attributes()->template;
229250 if( $schema_to_inherit !=null && $template_to_inherit != null ) {
230251 $inheritedSchemaObj = new PSSchema( $schema_to_inherit );
231 - $inherited_templates = $inheritedSchemaObj->getTemplates();
 252+ $inherited_templates = $inheritedSchemaObj->getTemplates();
232253 foreach( $inherited_templates as $inherited_template ) {
233254 if( $template_to_inherit == $inherited_template->getName() ){
234 - $inherited_fields = $inherited_template->getFields();
 255+ $inherited_fields = $inherited_template->getFields();
235256 }
236257 }
237258 }
@@ -239,12 +260,13 @@
240261 $this->label_name = (string)$child;
241262 } else if ( $child->getName() == "Field" ){
242263 $ignore = (string) $child->attributes()->ignore;
243 - if( $child->children() != null ){
 264+ wfDebugLog( 'myextension', 'Something is not right: ' . print_r( count($child->children()), true ) );
 265+ if( count($child->children()) > 1 ){ //@TODO :Can be dealt more efficiently
244266 $fieldObj = new PSTemplateField($child);
245267 $this->PSFields[$i++]= $fieldObj;
246268 }else if( $ignore != "true" ) {
247269 //Code to Add Templates from Inherited templates
248 - $field_name = (string) $child->attributes()->name;
 270+ $field_name = (string) $child->attributes()->name;
249271 foreach( $inherited_fields as $inherited_field ) {
250272 if( $field_name == $inherited_field->getName() ){
251273 $this->PSFields[$i++]= $inherited_field;
@@ -278,13 +300,13 @@
279301 $this->fieldXml = $field_xml;
280302 $this->fieldName = (string)$this->fieldXml->attributes()->name;
281303 if( ((string)$this->fieldXml->attributes()->list) == "list") {
282 - $this->list_values = true;
 304+ $this->list_values = true;
283305 }
284306 foreach ($this->fieldXml->children() as $tag => $child ) {
285307 if ( $tag == 'Label' ) {
286 - $this->fieldLabel = (string)$child;
287 - }
288 - }
 308+ $this->fieldLabel = (string)$child;
 309+ }
 310+ }
289311 }
290312 function getName(){
291313 return $this->fieldName;

Status & tagging log