r90116 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90115‎ | r90116 | r90117 >
Date:15:59, 15 June 2011
Author:ankitgarg833
Status:deferred
Tags:
Comment:
Adding hard-coded pageXml for testing purpose. registering Hook code
Modified paths:
  • /trunk/extensions/PageSchemas/PageSchemas.classes.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PageSchemas/PageSchemas.classes.php
@@ -76,7 +76,6 @@
7777 }
7878 return $text;
7979 }
80 -
8180 static function parseTemplate ( $template_xml ) {
8281 $name = $template_xml->attributes()->name;
8382 $text = self::tableRowHTML('template_class', 'Template', $name);
@@ -84,16 +83,12 @@
8584 $text .= self::parseField($child);
8685 }
8786 return $text;
88 - }
89 -
90 -
91 -
 87+ }
9288 static function parseField ( $field_xml ) {
9389 $name = $field_xml->attributes()->name;
9490 $text = self::tableMessageRowHTML('paramDataField', $name, $field_xml);
9591 return $text;
9692 }
97 -
9893 }
9994
10095 /*class holds the PageScheme tag equivalent object */
@@ -102,7 +97,8 @@
10398
10499 public $categoryName="";
105100 public $pageId=0;
106 - public $pageXml="";
 101+ public $pageXml=null;
 102+ public $pageXmlstr= "";
107103 public $pageName="";
108104
109105 /* Stores the templte objects */
@@ -110,26 +106,26 @@
111107
112108 function __construct ( $category_name ) {
113109 $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
117113 <ClassSchema name="City">
118 - <semanticforms:FormName>City</semanticforms:FormName>
 114+ <FormName>City</FormName>
119115 <Template name="City">
120116 <Field name="Population">
121 - <semanticmediawiki:Property name="Has population">
 117+ <Property name="Has population">
122118 <Type>Number</Type>
123 - </semanticmediawiki:Property>
124 - <semanticforms:FormInput>
 119+ </Property>
 120+ <FormInput>
125121 <InputType>text</InputType>
126122 <Size>20</Size>
127 - </semanticforms:FormInput>
128 - <semanticdrilldown:Filter>
 123+ </FormInput>
 124+ <Filter>
129125 <Label>Population</Label>
130 - </semanticdrilldown:Filter>
 126+ </Filter>
131127 </Field>
132128 </Template>
133 - <ClassSchema>
 129+ </ClassSchema>
134130 END;
135131
136132 /*
@@ -153,34 +149,36 @@
154150 //retrievimg the third attribute which is pp_value
155151 $pageXml = $row[2];
156152 */
157 - $pageName = $pageXml->attributes()->name;
 153+ $pageXml = simplexml_load_string ( $pageXmlstr );
 154+ $pageName = $pageXml->attributes()->name;
158155 /* index for template objects */
159156 $i = 0 ;
160157 foreach ( $pageXml->children() as $tag => $child ) {
161 - if ( $tag == 'Template' ) {
 158+ if ( $tag == 'Template' ) {
162159 $templateObj = new PSTemplate($child);
163 - $PSTemplates[$i++]= $templateObj;
 160+ $this->PSTemplates[$i++]= $templateObj;
164161 }
165162 }
 163+
166164 }
167165
168166 /* function to generate all pages based on the Xml contained in the page */
169167 function generateAllPages () {
170168 //Get templates
171 - $template_all = $this->getTemplates();
 169+ $template_all = $this->getTemplates();
172170 //For each template, Get Fields
173171 foreach ( $template_all as $template ) {
174172 $field_all = $template->getFields();
175173 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
177175 wfRunHooks( 'PageSchemasGeneratePages', array( $prop_array['name'], $prop_array['Type'] ) );
178176 }
179177 }
180178 }
181179
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;
185183 }
186184
187185 /*returns the name of the PageSchema object */
@@ -192,40 +190,40 @@
193191 /* Stores the field objects */
194192 public $PSFields = array();
195193 public $templateName ="";
196 - public $templateXml ="";
 194+ public $templateXml = null;
197195 function __construct( $template_xml ) {
198196 $templateXml = $template_xml;
199197 $templateName = $templateXml->attributes()->name;
200 - /* index for template objects */
 198+ /*index for template objects */
201199 $i = 0 ;
202 - foreach ($templateXml->children() as $child) {
 200+ foreach ($templateXml->children() as $child) {
203201 $fieldObj = new PSTemplateField($child);
204 - $PSFields[$i++]= $fieldObj;
 202+ $this->PSFields[$i++]= $fieldObj;
205203 }
206204 }
207205 function getName(){
208 - return $templateName;
 206+ return $this->templateName;
209207 }
210 - static function getFields(){
211 - return $PSFields;
 208+ function getFields(){
 209+ return $this->PSFields;
212210 }
213211 }
214212
215213 class PSTemplateField {
216214
217215 public $fieldName ="";
218 - public $fieldXml= "";
 216+ public $fieldXml= null;
219217
220218 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;
223221 }
224222 function getName(){
225 - return $fieldName;
 223+ return $this->fieldName;
226224 }
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 ) );
230228 return $object;
231229 }
232230 }

Status & tagging log