Index: trunk/extensions/PageSchemas/PageSchemas.classes.php |
— | — | @@ -76,7 +76,6 @@ |
77 | 77 | } |
78 | 78 | return $text; |
79 | 79 | } |
80 | | - |
81 | 80 | static function parseTemplate ( $template_xml ) { |
82 | 81 | $name = $template_xml->attributes()->name; |
83 | 82 | $text = self::tableRowHTML('template_class', 'Template', $name); |
— | — | @@ -84,16 +83,12 @@ |
85 | 84 | $text .= self::parseField($child); |
86 | 85 | } |
87 | 86 | return $text; |
88 | | - } |
89 | | - |
90 | | - |
91 | | - |
| 87 | + } |
92 | 88 | static function parseField ( $field_xml ) { |
93 | 89 | $name = $field_xml->attributes()->name; |
94 | 90 | $text = self::tableMessageRowHTML('paramDataField', $name, $field_xml); |
95 | 91 | return $text; |
96 | 92 | } |
97 | | - |
98 | 93 | } |
99 | 94 | |
100 | 95 | /*class holds the PageScheme tag equivalent object */ |
— | — | @@ -102,7 +97,8 @@ |
103 | 98 | |
104 | 99 | public $categoryName=""; |
105 | 100 | public $pageId=0; |
106 | | - public $pageXml=""; |
| 101 | + public $pageXml=null; |
| 102 | + public $pageXmlstr= ""; |
107 | 103 | public $pageName=""; |
108 | 104 | |
109 | 105 | /* Stores the templte objects */ |
— | — | @@ -110,26 +106,26 @@ |
111 | 107 | |
112 | 108 | function __construct ( $category_name ) { |
113 | 109 | $this->categoryName = $category_name; |
114 | | - $title = Title::newFromText( $categoryName, NS_CATEGORY ); |
115 | | - $pageId = $title->getArticleID(); |
116 | | - $pageXml =<<<END |
| 110 | + $title = Title::newFromText( $category_name, NS_CATEGORY ); |
| 111 | + $pageId = $title->getArticleID(); |
| 112 | + $pageXmlstr =<<<END |
117 | 113 | <ClassSchema name="City"> |
118 | | - <semanticforms:FormName>City</semanticforms:FormName> |
| 114 | + <FormName>City</FormName> |
119 | 115 | <Template name="City"> |
120 | 116 | <Field name="Population"> |
121 | | - <semanticmediawiki:Property name="Has population"> |
| 117 | + <Property name="Has population"> |
122 | 118 | <Type>Number</Type> |
123 | | - </semanticmediawiki:Property> |
124 | | - <semanticforms:FormInput> |
| 119 | + </Property> |
| 120 | + <FormInput> |
125 | 121 | <InputType>text</InputType> |
126 | 122 | <Size>20</Size> |
127 | | - </semanticforms:FormInput> |
128 | | - <semanticdrilldown:Filter> |
| 123 | + </FormInput> |
| 124 | + <Filter> |
129 | 125 | <Label>Population</Label> |
130 | | - </semanticdrilldown:Filter> |
| 126 | + </Filter> |
131 | 127 | </Field> |
132 | 128 | </Template> |
133 | | - <ClassSchema> |
| 129 | + </ClassSchema> |
134 | 130 | END; |
135 | 131 | |
136 | 132 | /* |
— | — | @@ -153,34 +149,36 @@ |
154 | 150 | //retrievimg the third attribute which is pp_value |
155 | 151 | $pageXml = $row[2]; |
156 | 152 | */ |
157 | | - $pageName = $pageXml->attributes()->name; |
| 153 | + $pageXml = simplexml_load_string ( $pageXmlstr ); |
| 154 | + $pageName = $pageXml->attributes()->name; |
158 | 155 | /* index for template objects */ |
159 | 156 | $i = 0 ; |
160 | 157 | foreach ( $pageXml->children() as $tag => $child ) { |
161 | | - if ( $tag == 'Template' ) { |
| 158 | + if ( $tag == 'Template' ) { |
162 | 159 | $templateObj = new PSTemplate($child); |
163 | | - $PSTemplates[$i++]= $templateObj; |
| 160 | + $this->PSTemplates[$i++]= $templateObj; |
164 | 161 | } |
165 | 162 | } |
| 163 | + |
166 | 164 | } |
167 | 165 | |
168 | 166 | /* function to generate all pages based on the Xml contained in the page */ |
169 | 167 | function generateAllPages () { |
170 | 168 | //Get templates |
171 | | - $template_all = $this->getTemplates(); |
| 169 | + $template_all = $this->getTemplates(); |
172 | 170 | //For each template, Get Fields |
173 | 171 | foreach ( $template_all as $template ) { |
174 | 172 | $field_all = $template->getFields(); |
175 | 173 | foreach( $field_all as $field ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type |
176 | | - $prop_array = $field->getObject('semanticmediawiki:Property'); //this returns an array with property values filled |
| 174 | + $prop_array = $field->getObject('Property'); //this returns an array with property values filled |
177 | 175 | wfRunHooks( 'PageSchemasGeneratePages', array( $prop_array['name'], $prop_array['Type'] ) ); |
178 | 176 | } |
179 | 177 | } |
180 | 178 | } |
181 | 179 | |
182 | | - /*return an array of PSTemplate Objects */ |
183 | | - static function getTemplates () { |
184 | | - return PSTemplates; |
| 180 | + /*return an array of PSTemplate Objects */ |
| 181 | + function getTemplates () { |
| 182 | + return $this->PSTemplates; |
185 | 183 | } |
186 | 184 | |
187 | 185 | /*returns the name of the PageSchema object */ |
— | — | @@ -192,40 +190,40 @@ |
193 | 191 | /* Stores the field objects */ |
194 | 192 | public $PSFields = array(); |
195 | 193 | public $templateName =""; |
196 | | - public $templateXml =""; |
| 194 | + public $templateXml = null; |
197 | 195 | function __construct( $template_xml ) { |
198 | 196 | $templateXml = $template_xml; |
199 | 197 | $templateName = $templateXml->attributes()->name; |
200 | | - /* index for template objects */ |
| 198 | + /*index for template objects */ |
201 | 199 | $i = 0 ; |
202 | | - foreach ($templateXml->children() as $child) { |
| 200 | + foreach ($templateXml->children() as $child) { |
203 | 201 | $fieldObj = new PSTemplateField($child); |
204 | | - $PSFields[$i++]= $fieldObj; |
| 202 | + $this->PSFields[$i++]= $fieldObj; |
205 | 203 | } |
206 | 204 | } |
207 | 205 | function getName(){ |
208 | | - return $templateName; |
| 206 | + return $this->templateName; |
209 | 207 | } |
210 | | - static function getFields(){ |
211 | | - return $PSFields; |
| 208 | + function getFields(){ |
| 209 | + return $this->PSFields; |
212 | 210 | } |
213 | 211 | } |
214 | 212 | |
215 | 213 | class PSTemplateField { |
216 | 214 | |
217 | 215 | public $fieldName =""; |
218 | | - public $fieldXml= ""; |
| 216 | + public $fieldXml= null; |
219 | 217 | |
220 | 218 | function __construct( $field_xml ) { |
221 | | - $fieldXml = $field_xml; |
222 | | - $fieldXml = $templateXml->attributes()->name; |
| 219 | + $this->fieldXml = $field_xml; |
| 220 | + $this->fieldName = $this->fieldXml->attributes()->name; |
223 | 221 | } |
224 | 222 | function getName(){ |
225 | | - return $fieldName; |
| 223 | + return $this->fieldName; |
226 | 224 | } |
227 | | - public function getObject( $objectName ) { |
228 | | - $object = null; |
229 | | - wfRunHooks( 'PageSchemasGetObject', array( $objectName, $this->fieldXml, $object ) ); |
| 225 | + function getObject( $objectName ) { |
| 226 | + $object = array(); |
| 227 | + wfRunHooks( 'PageSchemasGetObject', array( $objectName, $this->fieldXml, &$object ) ); |
230 | 228 | return $object; |
231 | 229 | } |
232 | 230 | } |