Index: trunk/extensions/PageSchemas/PageSchemas.classes.php |
— | — | @@ -8,7 +8,32 @@ |
9 | 9 | |
10 | 10 | class PageSchemas { |
11 | 11 | |
| 12 | + |
12 | 13 | /* 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 | + } |
13 | 38 | public static function validateXML( $xml, &$error_msg ) { |
14 | 39 | |
15 | 40 | |
— | — | @@ -98,10 +123,9 @@ |
99 | 124 | /*class holds the PageScheme tag equivalent object */ |
100 | 125 | |
101 | 126 | class PSSchema { |
102 | | - |
103 | 127 | public $categoryName=""; |
104 | 128 | public $pageId=0; |
105 | | - public $pageXml=null; |
| 129 | + public $pageXml=null; |
106 | 130 | public $pageXmlstr= ""; |
107 | 131 | public $pageName=""; |
108 | 132 | public $formName=""; |
— | — | @@ -118,7 +142,7 @@ |
119 | 143 | array( |
120 | 144 | 'pp_page', |
121 | 145 | 'pp_propname', |
122 | | - 'pp_value' |
| 146 | + 'pp_value' |
123 | 147 | ), |
124 | 148 | array( |
125 | 149 | 'pp_page' => $this->pageId, |
— | — | @@ -129,15 +153,34 @@ |
130 | 154 | $row = $dbr->fetchRow( $res ); |
131 | 155 | //retrievimg the third attribute which is pp_value |
132 | 156 | $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; |
135 | 159 | /* index for template objects */ |
136 | | - $i = 0 ; |
| 160 | + $i = 0; |
| 161 | + $inherited_templates = null ; |
137 | 162 | 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 | + } |
141 | 169 | } |
| 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 | + } |
142 | 185 | if ( $tag == 'FormName' ) { |
143 | 186 | $this->formName = (string)$child; |
144 | 187 | } |
— | — | @@ -160,8 +203,7 @@ |
161 | 204 | } |
162 | 205 | function getCategoryName(){ |
163 | 206 | return $this->categoryName; |
164 | | - } |
165 | | - |
| 207 | + } |
166 | 208 | } |
167 | 209 | class PSTemplate { |
168 | 210 | /* Stores the field objects */ |
— | — | @@ -178,12 +220,37 @@ |
179 | 221 | } |
180 | 222 | /*index for template objects */ |
181 | 223 | $i = 0 ; |
| 224 | + $inherited_fields = null ; |
182 | 225 | 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 |
184 | 240 | $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 | + } |
188 | 255 | } |
189 | 256 | } |
190 | 257 | } |
— | — | @@ -198,7 +265,7 @@ |
199 | 266 | } |
200 | 267 | function getFields(){ |
201 | 268 | return $this->PSFields; |
202 | | - } |
| 269 | + } |
203 | 270 | } |
204 | 271 | |
205 | 272 | class PSTemplateField { |