r95789 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95788‎ | r95789 | r95790 >
Date:16:19, 30 August 2011
Author:yaron
Status:deferred
Tags:
Comment:
Page Schemas 'getXmlTextForFieldInputs' hook was replaced with 'PageSchemasGetFieldXML'; plus general cleanup
Modified paths:
  • /trunk/extensions/SemanticDrilldown/SemanticDrilldown.php (modified) (history)
  • /trunk/extensions/SemanticDrilldown/includes/SD_Utils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticDrilldown/includes/SD_Utils.php
@@ -10,8 +10,8 @@
1111 class SDUtils {
1212
1313 /**
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+ */
1616 public static function createPageSchemasObject( $objectName, $xmlForField, &$object ) {
1717 $sdarray = array();
1818 if ( $objectName == "semanticdrilldown_Filter" ) {
@@ -30,13 +30,13 @@
3131 }
3232 }
3333 }
34 - //Setting value specific to SF in 'sf' index.
35 - $object['sd'] = $sdarray;
 34+ $object['sd'] = $sdarray;
3635 }
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 = "";
4141 $name_label = wfMsg( 'sd_createfilter_name' );
4242 $property_label = wfMsg( 'sd_createfilter_property' );
4343 $label_label = wfMsg( 'sd_createfilter_label' );
@@ -58,172 +58,158 @@
5959 $date_range_label = wfMsg( 'sd_filter_daterange' );
6060 $date_range_value = wfMsgForContent( 'sd_filter_daterange' );
6161 $require_filter_label = wfMsg( 'sd_createfilter_requirefilter' );
62 -
 62+
6363 $template_fields = array();
64 - $html_text = "";
 64+ $html_text = "";
6565 $template_all = $pageSchemaObj->getTemplates();
6666 $html_text_array = array();
6767 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
7070 foreach( $field_all as $field ) {
7171 $html_text .= '<fieldset style="background: #FDD;"><legend>Filter</legend>';
72 - $field_count++;
 72+ $field_count++;
7373 $sd_array = $field->getObject('semanticdrilldown_Filter');//this returns an array with property values filled
7474 $filter_array = $sd_array['sd'];
7575 $html_text .= '<p>'.$name_label.' <input size="25" name="sd_filter_name_starter" value="'.$filter_array['Label'].'" ></p>';
7676 $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();
8980 $option_html_text = "";
9081 foreach ( $categories as $category ) {
9182 $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";
9784 }
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.'
10188 <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.'
109109 <select id="time_period_dropdown" name="sd_time_period_starter">';
110110
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>
113113 <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>
116116 <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.'
125123 <select id="time_period_dropdown" name="sd_time_period_starter">
126124 <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>
129128 </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.'" >
140137 </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="">
144141 </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.'
149145 <select id="input_type_dropdown" name="sd_input_type_starter">
150146 <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
154158 </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 = "";
166166 }
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>';
175167 }
176 -
177 - $html_text .= '</fieldset>';
178 - $html_text_array[] = $html_text;
179 - $html_text = "";
180 - }
181 - }
182168 $text_extensions['sd'] = $html_text_array;
183169 return true;
184170 }
185 - public static function getXMLTextForPS( $wgRequest, &$text_extensions ){
186 - $Xmltext = "";
 171+
 172+ public static function getFieldXMLForPS( $request, &$xmlArray ) {
187173 $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_') {
195181 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' ) {
200186 $filter_mannual_values_str = $wgRequest->getText('sd_filter_values_'.$templateNum);
201187 // replace the comma substitution character that has no chance of
202188 // being included in the values list - namely, the ASCII beep
203189 $listSeparator = ',';
204190 $filter_mannual_values_str = str_replace( "\\$listSeparator", "\a", $filter_mannual_values_str );
205191 $filter_mannual_values_array = explode( $listSeparator, $filter_mannual_values_str );
206 - $Xmltext .= '<Values>';
 192+ $xml .= '<Values>';
207193 foreach ( $filter_mannual_values_array as $i => $value ) {
208194 // replace beep back with comma, trim
209195 $value = str_replace( "\a", $listSeparator, trim( $value ) );
210 - $Xmltext .= '<Value>'.$value.'</Value>';
 196+ $xml .= '<Value>'.$value.'</Value>';
211197 }
212 - $Xmltext .= '</Values>';
 198+ $xml .= '</Values>';
213199 }
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;
219204 }
220205 }
221 -
222 - $text_extensions['sd'] = $xml_text_array;
 206+
 207+ $xmlArray['sd'] = $xmlPerField;
223208 return true;
224209 }
225 - public static function getHtmlTextForPS( &$js_extensions ,&$text_extensions ) {
 210+
 211+ public static function getHtmlTextForPS( &$js_extensions ,&$text_extensions ) {
226212 global $wgContLang;
227 -
 213+
228214 $text = "";
229215 $text .= '<fieldset style="background: #FDD;"><legend>Filter</legend>';
230216 $name_label = wfMsg( 'sd_createfilter_name' );
@@ -251,7 +237,7 @@
252238 $date_range_value = wfMsgForContent( 'sd_filter_daterange' );
253239 $require_filter_label = wfMsg( 'sd_createfilter_requirefilter' );
254240 $text .= <<<END
255 -
 241+
256242 <p><input type="radio" name="sd_values_source_starter" checked value="property">
257243 $values_from_property_label
258244 </p>
@@ -260,7 +246,7 @@
261247 <select id="category_dropdown" name="sd_category_name_starter">
262248
263249 END;
264 -
 250+
265251 $categories = SDUtils::getTopLevelCategories();
266252 foreach ( $categories as $category ) {
267253 $category = str_replace( '_', ' ', $category );
@@ -289,13 +275,13 @@
290276 </fieldset>
291277
292278 END;
293 -
 279+
294280 $text_extensions['sd'] = $text;
295281 return true;
296282 }
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+ */
300286 public static function parseFieldElements( $field_xml, &$text_object ) {
301287 foreach ( $field_xml->children() as $tag => $child ) {
302288 if ( $tag == "semanticdrilldown_Filter" ) {
@@ -486,8 +472,8 @@
487473 if ( class_exists( 'PSSchema' ) ) {
488474 $pageSchemaObj = new PSSchema( $category );
489475 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);
492478 return $result_filters;
493479 }
494480 }
@@ -497,7 +483,7 @@
498484 /**
499485 * Gets all the display parameters defined for a category
500486 */
501 - static function getDisplayParamsForCategory( $category ) {
 487+ static function getDisplayParamsForCategory( $category ) {
502488 $all_display_params = SDUtils::getValuesForProperty( str_replace( ' ', '_', $category ), NS_CATEGORY, '_SD_DP' );
503489
504490 $return_display_params = array();
@@ -675,7 +661,7 @@
676662 $magicWordVariableIDs[] = 'MAG_SHOWINDRILLDOWN';
677663 return true;
678664 }
679 -
 665+
680666 /**
681667 * Set the actual value of the magic words
682668 */
Index: trunk/extensions/SemanticDrilldown/SemanticDrilldown.php
@@ -70,7 +70,7 @@
7171 $wgHooks['PSParseFieldElements'][] = 'SDUtils::parseFieldElements' ; //Hook for creating Pages
7272 $wgHooks['PageSchemasGetObject'][] = 'SDUtils::createPageSchemasObject' ; //Hook for returning PageSchema(extension) object from a given xml
7373 $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
7575 $wgHooks['getFilledHtmlTextForFieldInputs'][] = 'SDUtils::getFilledHtmlTextForPS' ; //Hook for retuning html text to PS schema
7676
7777