Index: trunk/extensions/SemanticDrilldown/includes/SD_Utils.php |
— | — | @@ -10,8 +10,8 @@ |
11 | 11 | class SDUtils { |
12 | 12 | |
13 | 13 | /** |
14 | | -* Function to return the Property based on the xml passed from the PageSchema extension |
15 | | -*/ |
| 14 | + * Function to return the Property based on the xml passed from the PageSchema extension |
| 15 | + */ |
16 | 16 | public static function createPageSchemasObject( $objectName, $xmlForField, &$object ) { |
17 | 17 | $sdarray = array(); |
18 | 18 | if ( $objectName == "semanticdrilldown_Filter" ) { |
— | — | @@ -30,13 +30,13 @@ |
31 | 31 | } |
32 | 32 | } |
33 | 33 | } |
34 | | - //Setting value specific to SF in 'sf' index. |
35 | | - $object['sd'] = $sdarray; |
| 34 | + $object['sd'] = $sdarray; |
36 | 35 | } |
37 | | - return true; |
38 | | -} |
39 | | - public static function getFilledHtmlTextForPS( $pageSchemaObj, &$text_extensions ){ |
40 | | - $text = ""; |
| 36 | + return true; |
| 37 | + } |
| 38 | + |
| 39 | + public static function getFilledHtmlTextForPS( $pageSchemaObj, &$text_extensions ){ |
| 40 | + $text = ""; |
41 | 41 | $name_label = wfMsg( 'sd_createfilter_name' ); |
42 | 42 | $property_label = wfMsg( 'sd_createfilter_property' ); |
43 | 43 | $label_label = wfMsg( 'sd_createfilter_label' ); |
— | — | @@ -58,172 +58,158 @@ |
59 | 59 | $date_range_label = wfMsg( 'sd_filter_daterange' ); |
60 | 60 | $date_range_value = wfMsgForContent( 'sd_filter_daterange' ); |
61 | 61 | $require_filter_label = wfMsg( 'sd_createfilter_requirefilter' ); |
62 | | - |
| 62 | + |
63 | 63 | $template_fields = array(); |
64 | | - $html_text = ""; |
| 64 | + $html_text = ""; |
65 | 65 | $template_all = $pageSchemaObj->getTemplates(); |
66 | 66 | $html_text_array = array(); |
67 | 67 | foreach ( $template_all as $template ) { |
68 | | - $field_all = $template->getFields(); |
69 | | - $field_count = 0; //counts the number of fields |
| 68 | + $field_all = $template->getFields(); |
| 69 | + $field_count = 0; //counts the number of fields |
70 | 70 | foreach( $field_all as $field ) { |
71 | 71 | $html_text .= '<fieldset style="background: #FDD;"><legend>Filter</legend>'; |
72 | | - $field_count++; |
| 72 | + $field_count++; |
73 | 73 | $sd_array = $field->getObject('semanticdrilldown_Filter');//this returns an array with property values filled |
74 | 74 | $filter_array = $sd_array['sd']; |
75 | 75 | $html_text .= '<p>'.$name_label.' <input size="25" name="sd_filter_name_starter" value="'.$filter_array['Label'].'" ></p>'; |
76 | 76 | $html_text .= '<p><input type="radio" name="sd_values_source_starter" checked value="property">'. |
77 | | - $values_from_property_label.' |
78 | | - </p>'; |
79 | | - $categories = SDUtils::getTopLevelCategories(); |
80 | | - $option_html_text = ""; |
81 | | - foreach ( $categories as $category ) { |
82 | | - $category = str_replace( '_', ' ', $category ); |
83 | | - $option_html_text .= " <option>$category</option>\n"; |
84 | | - } |
85 | | - if( $filter_array['ValuesFromCategory'] != null){ |
86 | | - $html_text .= '<p><input type="radio" name="sd_values_source_starter" checked value="category">'. |
87 | | - $values_from_category_label.' |
88 | | - <select id="category_dropdown" name="sd_category_name_starter">'; |
| 77 | + $values_from_property_label.' |
| 78 | + </p>'; |
| 79 | + $categories = SDUtils::getTopLevelCategories(); |
89 | 80 | $option_html_text = ""; |
90 | 81 | foreach ( $categories as $category ) { |
91 | 82 | $category = str_replace( '_', ' ', $category ); |
92 | | - if( $category == $filter_array["ValuesFromCategory"]) { |
93 | | - $option_html_text .= ' <option selected>'.$category.'</option>\n'; |
94 | | - }else{ |
95 | | - $option_html_text .= ' <option>'.$category.'</option>\n'; |
96 | | - } |
| 83 | + $option_html_text .= " <option>$category</option>\n"; |
97 | 84 | } |
98 | | - }else{ |
99 | | - $html_text .= '<p><input type="radio" name="sd_values_source_starter" value="category">'. |
100 | | - $values_from_category_label.' |
| 85 | + if( $filter_array['ValuesFromCategory'] != null){ |
| 86 | + $html_text .= '<p><input type="radio" name="sd_values_source_starter" checked value="category">'. |
| 87 | + $values_from_category_label.' |
101 | 88 | <select id="category_dropdown" name="sd_category_name_starter">'; |
102 | | - } |
103 | | - $html_text .= $option_html_text; |
104 | | - $html_text .= '</select></p>'; |
105 | | - |
106 | | - if( $filter_array["TimePeriod"] != null ){ |
107 | | - $html_text .= '<p><input type="radio" name="sd_values_source_starter" checked value="dates">'. |
108 | | - $date_values_label.' |
| 89 | + $option_html_text = ""; |
| 90 | + foreach ( $categories as $category ) { |
| 91 | + $category = str_replace( '_', ' ', $category ); |
| 92 | + if( $category == $filter_array["ValuesFromCategory"]) { |
| 93 | + $option_html_text .= ' <option selected>'.$category.'</option>\n'; |
| 94 | + }else{ |
| 95 | + $option_html_text .= ' <option>'.$category.'</option>\n'; |
| 96 | + } |
| 97 | + } |
| 98 | + } else { |
| 99 | + $html_text .= '<p><input type="radio" name="sd_values_source_starter" value="category">'. |
| 100 | + $values_from_category_label.' |
| 101 | + <select id="category_dropdown" name="sd_category_name_starter">'; |
| 102 | + } |
| 103 | + $html_text .= $option_html_text; |
| 104 | + $html_text .= '</select></p>'; |
| 105 | + |
| 106 | + if ( $filter_array["TimePeriod"] != null ){ |
| 107 | + $html_text .= '<p><input type="radio" name="sd_values_source_starter" checked value="dates">'. |
| 108 | + $date_values_label.' |
109 | 109 | <select id="time_period_dropdown" name="sd_time_period_starter">'; |
110 | 110 | |
111 | | - if($filter_array['TimePeriod'] == $year_value ){ |
112 | | - $html_text .= '<option selected value="'.$year_value.'">'.$year_label.'</option> |
| 111 | + if($filter_array['TimePeriod'] == $year_value ){ |
| 112 | + $html_text .= '<option selected value="'.$year_value.'">'.$year_label.'</option> |
113 | 113 | <option value="'.$month_value.'">'.$month_label.'</option>'; |
114 | | - }else{ |
115 | | - $html_text .= '<option value="'.$year_value.'">'.$year_label.'</option> |
| 114 | + }else{ |
| 115 | + $html_text .= '<option value="'.$year_value.'">'.$year_label.'</option> |
116 | 116 | <option selected value="'.$month_value.'">'.$month_label.'</option>'; |
117 | | - } |
118 | | - |
119 | | - $html_text .= '</select> |
120 | | - </p>'; |
121 | | - |
122 | | - }else{ |
123 | | - $html_text .= '<p><input type="radio" name="sd_values_source_starter" value="dates">'. |
124 | | - $date_values_label.' |
| 117 | + } |
| 118 | + |
| 119 | + |
| 120 | + } else { |
| 121 | + $html_text .= '<p><input type="radio" name="sd_values_source_starter" value="dates">'. |
| 122 | + $date_values_label.' |
125 | 123 | <select id="time_period_dropdown" name="sd_time_period_starter"> |
126 | 124 | <option value="'.$year_value.'">'.$year_label.'</option> |
127 | | - <option value="'.$month_value.'">'.$month_label.'</option> |
128 | | - </select> |
| 125 | + <option value="'.$month_value.'">'.$month_label.'</option>'; |
| 126 | + } |
| 127 | + $html_text .= '</select> |
129 | 128 | </p>'; |
130 | | - } |
131 | | - if( $filter_array['Values'] != null){ |
132 | | - $values_array = $filter_array['Values']; |
133 | | - $values_str = ""; |
134 | | - foreach($values_array as $value) |
135 | | - { |
136 | | - $values_str .= $value.', '; |
137 | | - } |
138 | | - $html_text .= '<p><input type="radio" name="sd_values_source_starter" checked value="manual">'. |
139 | | - $enter_values_label.' <input size="40" name="sd_filter_values_starter" value=".'.$values_str.'" > |
| 129 | + if( $filter_array['Values'] != null){ |
| 130 | + $values_array = $filter_array['Values']; |
| 131 | + $values_str = ""; |
| 132 | + foreach($values_array as $value) { |
| 133 | + $values_str .= $value.', '; |
| 134 | + } |
| 135 | + $html_text .= '<p><input type="radio" name="sd_values_source_starter" checked value="manual">'. |
| 136 | + $enter_values_label.' <input size="40" name="sd_filter_values_starter" value=".'.$values_str.'" > |
140 | 137 | </p>'; |
141 | | - }else{ |
142 | | - $html_text .= '<p><input type="radio" name="sd_values_source_starter" value="manual">'. |
143 | | - $enter_values_label.' <input size="40" name="sd_filter_values_starter" value=""> |
| 138 | + }else{ |
| 139 | + $html_text .= '<p><input type="radio" name="sd_values_source_starter" value="manual">'. |
| 140 | + $enter_values_label.' <input size="40" name="sd_filter_values_starter" value=""> |
144 | 141 | </p>'; |
145 | | - } |
146 | | - if( $filter_array['InputType'] != null){ |
147 | | - $input_type_val = $filter_array['InputType']; |
148 | | - $html_text .= '<p>'.$input_type_label.' |
| 142 | + } |
| 143 | + $input_type_val = $filter_array['InputType']; |
| 144 | + $html_text .= '<p>'.$input_type_label.' |
149 | 145 | <select id="input_type_dropdown" name="sd_input_type_starter"> |
150 | 146 | <option selected value="">'.$values_list_label.'</option>'; |
151 | | - if( $input_type_val == $combo_box_value){ |
152 | | - $html_text .= '<option selected value="'.$combo_box_value.'">'.$combo_box_label.'</option> |
153 | | - <option value="'.$date_range_value.'">'.$date_range_label.'</option> |
| 147 | + if ( $input_type_val == $combo_box_value ) { |
| 148 | + $html_text .= '<option selected value="'.$combo_box_value.'">'.$combo_box_label.'</option> |
| 149 | + <option value="'.$date_range_value.'">'.$date_range_label.'</option>'; |
| 150 | + } elseif ( $input_type_val == $date_range_value ) { |
| 151 | + $html_text .= '<option value="'.$combo_box_value.'">'.$combo_box_label.'</option> |
| 152 | + <option selected value="'.$date_range_value.'">'.$date_range_label.'</option>'; |
| 153 | + } else { |
| 154 | + $html_text .= '<option value="'.$combo_box_value.'">'.$combo_box_label.'</option> |
| 155 | + <option value="'.$date_range_value.'">'.$date_range_label.'</option>'; |
| 156 | + } |
| 157 | + $html_text .= <<<END |
154 | 158 | </select> |
155 | | - </p>'; |
156 | | - }else if( $input_type_val == $date_range_value ){ |
157 | | - $html_text .= '<option value="'.$combo_box_value.'">'.$combo_box_label.'</option> |
158 | | - <option selected value="'.$date_range_value.'">'.$date_range_label.'</option> |
159 | | - </select> |
160 | | - </p>'; |
161 | | - }else{ |
162 | | - $html_text .= '<option value="'.$combo_box_value.'">'.$combo_box_label.'</option> |
163 | | - <option value="'.$date_range_value.'">'.$date_range_label.'</option> |
164 | | - </select> |
165 | | - </p>'; |
| 159 | + </p> |
| 160 | + </fieldset> |
| 161 | + |
| 162 | +END; |
| 163 | + |
| 164 | + $html_text_array[] = $html_text; |
| 165 | + $html_text = ""; |
166 | 166 | } |
167 | | - }else{ |
168 | | - $html_text .= '<p>'.$input_type_label.' |
169 | | - <select id="input_type_dropdown" name="sd_input_type_starter"> |
170 | | - <option selected value="">'.$values_list_label.'</option>'; |
171 | | - $html_text .= '<option value="'.$combo_box_value.'">'.$combo_box_label.'</option> |
172 | | - <option value="'.$date_range_value.'">'.$date_range_label.'</option> |
173 | | - </select> |
174 | | - </p>'; |
175 | 167 | } |
176 | | - |
177 | | - $html_text .= '</fieldset>'; |
178 | | - $html_text_array[] = $html_text; |
179 | | - $html_text = ""; |
180 | | - } |
181 | | - } |
182 | 168 | $text_extensions['sd'] = $html_text_array; |
183 | 169 | return true; |
184 | 170 | } |
185 | | - public static function getXMLTextForPS( $wgRequest, &$text_extensions ){ |
186 | | - $Xmltext = ""; |
| 171 | + |
| 172 | + public static function getFieldXMLForPS( $request, &$xmlArray ) { |
187 | 173 | $templateNum = -1; |
188 | | - $xml_text_array = array(); |
189 | | - foreach ( $wgRequest->getValues() as $var => $val ) { |
190 | | - if(substr($var,0,15) == 'sd_filter_name_'){ |
191 | | - $Xmltext .= '<semanticdrilldown_Filter>'; |
192 | | - $templateNum = substr($var,15,1); |
193 | | - $Xmltext .= '<Label>'.$val.'</Label>'; |
194 | | - }else if(substr($var,0,17) == 'sd_values_source_'){ |
| 174 | + $xmlPerField = array(); |
| 175 | + foreach ( $request->getValues() as $var => $val ) { |
| 176 | + if ( substr( $var, 0, 15 ) == 'sd_filter_name_' ) { |
| 177 | + $xml = '<semanticdrilldown_Filter>'; |
| 178 | + $templateNum = substr($var,15,1); |
| 179 | + $xml .= '<Label>'.$val.'</Label>'; |
| 180 | + } elseif ( substr( $var, 0, 17 ) == 'sd_values_source_') { |
195 | 181 | if ( $val == 'category' ) { |
196 | | - $Xmltext .= '<ValuesFromCategory>'.$wgRequest->getText('sd_category_name_'.$templateNum).'</ValuesFromCategory>'; |
197 | | - }else if ( $val == 'dates' ) { |
198 | | - $Xmltext .= '<TimePeriod>'.$wgRequest->getText('sd_time_period_'.$templateNum).'</TimePeriod>'; |
199 | | - }else if ( $val == 'manual' ) { |
| 182 | + $xml .= '<ValuesFromCategory>'.$wgRequest->getText('sd_category_name_'.$templateNum).'</ValuesFromCategory>'; |
| 183 | + } elseif ( $val == 'dates' ) { |
| 184 | + $xml .= '<TimePeriod>'.$wgRequest->getText('sd_time_period_'.$templateNum).'</TimePeriod>'; |
| 185 | + } elseif ( $val == 'manual' ) { |
200 | 186 | $filter_mannual_values_str = $wgRequest->getText('sd_filter_values_'.$templateNum); |
201 | 187 | // replace the comma substitution character that has no chance of |
202 | 188 | // being included in the values list - namely, the ASCII beep |
203 | 189 | $listSeparator = ','; |
204 | 190 | $filter_mannual_values_str = str_replace( "\\$listSeparator", "\a", $filter_mannual_values_str ); |
205 | 191 | $filter_mannual_values_array = explode( $listSeparator, $filter_mannual_values_str ); |
206 | | - $Xmltext .= '<Values>'; |
| 192 | + $xml .= '<Values>'; |
207 | 193 | foreach ( $filter_mannual_values_array as $i => $value ) { |
208 | 194 | // replace beep back with comma, trim |
209 | 195 | $value = str_replace( "\a", $listSeparator, trim( $value ) ); |
210 | | - $Xmltext .= '<Value>'.$value.'</Value>'; |
| 196 | + $xml .= '<Value>'.$value.'</Value>'; |
211 | 197 | } |
212 | | - $Xmltext .= '</Values>'; |
| 198 | + $xml .= '</Values>'; |
213 | 199 | } |
214 | | - }else if( substr($var,0,14) == 'sd_input_type_'){ |
215 | | - $Xmltext .= '<InputType>'.$val.'</InputType>'; |
216 | | - $Xmltext .= '</semanticdrilldown_Filter>'; |
217 | | - $xml_text_array[] = $Xmltext; |
218 | | - $Xmltext = ''; |
| 200 | + } elseif ( substr($var,0,14) == 'sd_input_type_') { |
| 201 | + $xml .= '<InputType>'.$val.'</InputType>'; |
| 202 | + $xml .= '</semanticdrilldown_Filter>'; |
| 203 | + $xmlPerField[] = $xml; |
219 | 204 | } |
220 | 205 | } |
221 | | - |
222 | | - $text_extensions['sd'] = $xml_text_array; |
| 206 | + |
| 207 | + $xmlArray['sd'] = $xmlPerField; |
223 | 208 | return true; |
224 | 209 | } |
225 | | - public static function getHtmlTextForPS( &$js_extensions ,&$text_extensions ) { |
| 210 | + |
| 211 | + public static function getHtmlTextForPS( &$js_extensions ,&$text_extensions ) { |
226 | 212 | global $wgContLang; |
227 | | - |
| 213 | + |
228 | 214 | $text = ""; |
229 | 215 | $text .= '<fieldset style="background: #FDD;"><legend>Filter</legend>'; |
230 | 216 | $name_label = wfMsg( 'sd_createfilter_name' ); |
— | — | @@ -251,7 +237,7 @@ |
252 | 238 | $date_range_value = wfMsgForContent( 'sd_filter_daterange' ); |
253 | 239 | $require_filter_label = wfMsg( 'sd_createfilter_requirefilter' ); |
254 | 240 | $text .= <<<END |
255 | | - |
| 241 | + |
256 | 242 | <p><input type="radio" name="sd_values_source_starter" checked value="property"> |
257 | 243 | $values_from_property_label |
258 | 244 | </p> |
— | — | @@ -260,7 +246,7 @@ |
261 | 247 | <select id="category_dropdown" name="sd_category_name_starter"> |
262 | 248 | |
263 | 249 | END; |
264 | | - |
| 250 | + |
265 | 251 | $categories = SDUtils::getTopLevelCategories(); |
266 | 252 | foreach ( $categories as $category ) { |
267 | 253 | $category = str_replace( '_', ' ', $category ); |
— | — | @@ -289,13 +275,13 @@ |
290 | 276 | </fieldset> |
291 | 277 | |
292 | 278 | END; |
293 | | - |
| 279 | + |
294 | 280 | $text_extensions['sd'] = $text; |
295 | 281 | return true; |
296 | 282 | } |
297 | | -/** |
298 | | - *Thi Function parses the Field elements in the xml of the pages. Hooks for PageSchemas extension |
299 | | -*/ |
| 283 | + /** |
| 284 | + * This function parses the Field elements in the xml of the pages. Hooks for Page Schemas extension |
| 285 | + */ |
300 | 286 | public static function parseFieldElements( $field_xml, &$text_object ) { |
301 | 287 | foreach ( $field_xml->children() as $tag => $child ) { |
302 | 288 | if ( $tag == "semanticdrilldown_Filter" ) { |
— | — | @@ -486,8 +472,8 @@ |
487 | 473 | if ( class_exists( 'PSSchema' ) ) { |
488 | 474 | $pageSchemaObj = new PSSchema( $category ); |
489 | 475 | if($pageSchemaObj->isPSDefined()){ |
490 | | - $filters_ps = SDFilter::loadAllFromPageSchema( $pageSchemaObj ); |
491 | | - $result_filters = array_merge($filters, $filters_ps); |
| 476 | + $filters_ps = SDFilter::loadAllFromPageSchema( $pageSchemaObj ); |
| 477 | + $result_filters = array_merge($filters, $filters_ps); |
492 | 478 | return $result_filters; |
493 | 479 | } |
494 | 480 | } |
— | — | @@ -497,7 +483,7 @@ |
498 | 484 | /** |
499 | 485 | * Gets all the display parameters defined for a category |
500 | 486 | */ |
501 | | - static function getDisplayParamsForCategory( $category ) { |
| 487 | + static function getDisplayParamsForCategory( $category ) { |
502 | 488 | $all_display_params = SDUtils::getValuesForProperty( str_replace( ' ', '_', $category ), NS_CATEGORY, '_SD_DP' ); |
503 | 489 | |
504 | 490 | $return_display_params = array(); |
— | — | @@ -675,7 +661,7 @@ |
676 | 662 | $magicWordVariableIDs[] = 'MAG_SHOWINDRILLDOWN'; |
677 | 663 | return true; |
678 | 664 | } |
679 | | - |
| 665 | + |
680 | 666 | /** |
681 | 667 | * Set the actual value of the magic words |
682 | 668 | */ |
Index: trunk/extensions/SemanticDrilldown/SemanticDrilldown.php |
— | — | @@ -70,7 +70,7 @@ |
71 | 71 | $wgHooks['PSParseFieldElements'][] = 'SDUtils::parseFieldElements' ; //Hook for creating Pages |
72 | 72 | $wgHooks['PageSchemasGetObject'][] = 'SDUtils::createPageSchemasObject' ; //Hook for returning PageSchema(extension) object from a given xml |
73 | 73 | $wgHooks['getHtmlTextForFieldInputs'][] = 'SDUtils::getHtmlTextForPS' ; //Hook for retuning html text to PS schema |
74 | | -$wgHooks['getXmlTextForFieldInputs'][] = 'SDUtils::getXMLTextForPS' ; //Hook for retuning html text to PS schema |
| 74 | +$wgHooks['PageSchemasGetFieldXML'][] = 'SDUtils::getFieldXMLForPS' ; //Hook for retuning html text to PS schema |
75 | 75 | $wgHooks['getFilledHtmlTextForFieldInputs'][] = 'SDUtils::getFilledHtmlTextForPS' ; //Hook for retuning html text to PS schema |
76 | 76 | |
77 | 77 | |