r92391 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92390‎ | r92391 | r92392 >
Date:13:23, 17 July 2011
Author:ankitgarg833
Status:deferred
Tags:
Comment:
adding 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,32 @@
99
1010 class PageSchemas {
1111
 12+
1213 /* Functions */
 14+ //Copied from SFUtils
 15+ public static function titleString( $title ) {
 16+ $namespace = $title->getNsText();
 17+ if ( $namespace != '' ) {
 18+ $namespace .= ':';
 19+ }
 20+ if ( self::isCapitalized( $title ) ) {
 21+ global $wgContLang;
 22+ return $namespace . $wgContLang->ucfirst( $title->getText() );
 23+ } else {
 24+ return $namespace . $title->getText();
 25+ }
 26+ }
 27+ public static function isCapitalized( $title ) {
 28+ // Method was added in MW 1.16.
 29+ $realFunction = array( 'MWNamespace', 'isCapitalized' );
 30+ if ( is_callable( $realFunction ) ) {
 31+ return MWNamespace::isCapitalized( $title->getNamespace() );
 32+ } else {
 33+ global $wgCapitalLinks;
 34+ return $wgCapitalLinks;
 35+ }
 36+
 37+ }
1338 public static function validateXML( $xml, &$error_msg ) {
1439
1540
@@ -98,10 +123,9 @@
99124 /*class holds the PageScheme tag equivalent object */
100125
101126 class PSSchema {
102 -
103127 public $categoryName="";
104128 public $pageId=0;
105 - public $pageXml=null;
 129+ public $pageXml=null;
106130 public $pageXmlstr= "";
107131 public $pageName="";
108132 public $formName="";
@@ -118,7 +142,7 @@
119143 array(
120144 'pp_page',
121145 'pp_propname',
122 - 'pp_value'
 146+ 'pp_value'
123147 ),
124148 array(
125149 'pp_page' => $this->pageId,
@@ -129,15 +153,34 @@
130154 $row = $dbr->fetchRow( $res );
131155 //retrievimg the third attribute which is pp_value
132156 $pageXmlstr = $row[2];
133 - $pageXml = simplexml_load_string ( $pageXmlstr );
134 - $this->pageName = (string)$pageXml->attributes()->name;
 157+ $pageXml = simplexml_load_string ( $pageXmlstr );
 158+ $this->pageName = (string)$pageXml->attributes()->name;
135159 /* index for template objects */
136 - $i = 0 ;
 160+ $i = 0;
 161+ $inherited_templates = null ;
137162 foreach ( $pageXml->children() as $tag => $child ) {
138 - if ( $tag == 'Template' ) {
139 - $templateObj = new PSTemplate($child);
140 - $this->PSTemplates[$i++]= $templateObj;
 163+ if ( $tag == 'InheritsFrom ' ) {
 164+ $schema_to_inherit = (string) $child->attributes()->schema;
 165+ if( $schema_to_inherit !=null ){
 166+ $inheritedSchemaObj = new PSSchema( $schema_to_inherit );
 167+ $inherited_templates = $inheritedSchemaObj->getTemplates();
 168+ }
141169 }
 170+ if ( $tag == 'Template' ) {
 171+ $ignore = (string) $child->attributes()->ignore;
 172+ if( $child->children() != null ){
 173+ $templateObj = new PSTemplate($child);
 174+ $this->PSTemplates[$i++]= $templateObj;
 175+ }else if( $ignore != "true" ) {
 176+ //Code to Add Templates from Inherited templates
 177+ $temp_name = (string) $child->attributes()->name;
 178+ foreach( $inherited_templates as $inherited_template ) {
 179+ if( $temp_name == $inherited_template->getName() ){
 180+ $this->PSTemplates[$i++] = $inherited_template;
 181+ }
 182+ }
 183+ }
 184+ }
142185 if ( $tag == 'FormName' ) {
143186 $this->formName = (string)$child;
144187 }
@@ -160,8 +203,7 @@
161204 }
162205 function getCategoryName(){
163206 return $this->categoryName;
164 - }
165 -
 207+ }
166208 }
167209 class PSTemplate {
168210 /* Stores the field objects */
@@ -178,12 +220,37 @@
179221 }
180222 /*index for template objects */
181223 $i = 0 ;
 224+ $inherited_fields = null ;
182225 foreach ($template_xml->children() as $child) {
183 - if( $child->getName() == "Label" ) { //@TODO Label => sf:Label
 226+ if ( $child->getName == 'InheritsFrom ' ) {
 227+ $schema_to_inherit = (string) $child->attributes()->schema;
 228+ $template_to_inherit = (string) $child->attributes()->template;
 229+ if( $schema_to_inherit !=null && $template_to_inherit != null ) {
 230+ $inheritedSchemaObj = new PSSchema( $schema_to_inherit );
 231+ $inherited_templates = $inheritedSchemaObj->getTemplates();
 232+ foreach( $inherited_templates as $inherited_template ) {
 233+ if( $template_to_inherit == $inherited_template->getName() ){
 234+ $inherited_fields = $inherited_template->getFields();
 235+ }
 236+ }
 237+ }
 238+ }
 239+ else if( $child->getName() == "Label" ) { //@TODO Label => sf:Label
184240 $this->label_name = (string)$child;
185 - }else{
186 - $fieldObj = new PSTemplateField($child);
187 - $this->PSFields[$i++]= $fieldObj;
 241+ } else if ( $child->getName() == "Field" ){
 242+ $ignore = (string) $child->attributes()->ignore;
 243+ if( $child->children() != null ){
 244+ $fieldObj = new PSTemplateField($child);
 245+ $this->PSFields[$i++]= $fieldObj;
 246+ }else if( $ignore != "true" ) {
 247+ //Code to Add Templates from Inherited templates
 248+ $field_name = (string) $child->attributes()->name;
 249+ foreach( $inherited_fields as $inherited_field ) {
 250+ if( $field_name == $inherited_field->getName() ){
 251+ $this->PSFields[$i++]= $inherited_field;
 252+ }
 253+ }
 254+ }
188255 }
189256 }
190257 }
@@ -198,7 +265,7 @@
199266 }
200267 function getFields(){
201268 return $this->PSFields;
202 - }
 269+ }
203270 }
204271
205272 class PSTemplateField {

Status & tagging log