Index: trunk/extensions/SemanticDrilldown/includes/SD_Filter.php |
— | — | @@ -24,42 +24,37 @@ |
25 | 25 | $template_all = $psSchemaObj->getTemplates(); |
26 | 26 | foreach ( $template_all as $template ) { |
27 | 27 | $field_all = $template->getFields(); |
28 | | - foreach( $field_all as $fieldObj ) { //for each Field, retrieve smw properties and fill $prop_name , $prop_type |
| 28 | + foreach( $field_all as $fieldObj ) { |
29 | 29 | $f = new SDFilter(); |
30 | | - $object_values = $fieldObj->getObject('semanticdrilldown_Filter'); |
31 | | - if ( !array_key_exists( 'sd', $object_values ) ) { |
32 | | - continue; |
33 | | - } |
34 | | - $sd_array = $object_values['sd']; |
35 | | - $smw_array = $fieldObj->getObject('semanticmediawiki_Property'); |
36 | | - if ( !array_key_exists( 'smw', $smw_array ) ) { |
| 30 | + $filter_array = $fieldObj->getObject( 'semanticdrilldown_Filter' ); |
| 31 | + if ( is_null( $filter_array ) ) { |
37 | 32 | continue; |
38 | 33 | } |
39 | | - $prop_array = $smw_array['smw']; |
40 | | - if ( array_key_exists( 'Name', $sd_array ) ) { |
41 | | - $f->name = $sd_array['Name']; |
| 34 | + if ( array_key_exists( 'Name', $filter_array ) ) { |
| 35 | + $f->name = $filter_array['Name']; |
42 | 36 | } else { |
43 | 37 | $f->name = $fieldObj->getName(); |
44 | 38 | } |
| 39 | + $prop_array = $fieldObj->getObject('semanticmediawiki_Property'); |
45 | 40 | $f->property = $prop_array['name']; |
46 | 41 | $f->escaped_property = str_replace( array( ' ', "'" ), array( '_', "\'" ), $f->property ); |
47 | 42 | $f->is_relation = true; |
48 | 43 | if ( array_key_exists( 'Type', $prop_array ) && $prop_array['Type'] != 'Page' ) { |
49 | 44 | $f->is_relation = false; |
50 | 45 | } |
51 | | - if ( array_key_exists( 'InputType', $sd_array ) ) { |
52 | | - $f->input_type = $sd_array['InputType']; |
| 46 | + if ( array_key_exists( 'InputType', $filter_array ) ) { |
| 47 | + $f->input_type = $filter_array['InputType']; |
53 | 48 | } |
54 | | - if ( array_key_exists( 'ValuesFromCategory', $sd_array ) ) { |
55 | | - $f->category = $sd_array['ValuesFromCategory']; |
| 49 | + if ( array_key_exists( 'ValuesFromCategory', $filter_array ) ) { |
| 50 | + $f->category = $filter_array['ValuesFromCategory']; |
56 | 51 | $f->allowed_values = SDUtils::getCategoryChildren( $f->category, false, 5 ); |
57 | | - } elseif ( array_key_exists( 'TimePeriod', $sd_array ) ) { |
58 | | - $f->time_period = $sd_array['TimePeriod']; |
| 52 | + } elseif ( array_key_exists( 'TimePeriod', $filter_array ) ) { |
| 53 | + $f->time_period = $filter_array['TimePeriod']; |
59 | 54 | $f->allowed_values = array(); |
60 | 55 | } elseif ( $f->is_boolean ) { |
61 | 56 | $f->allowed_values = array( '0', '1' ); |
62 | | - } elseif ( array_key_exists( 'Values', $sd_array ) ) { |
63 | | - $f->allowed_values = $sd_array['Values']; |
| 57 | + } elseif ( array_key_exists( 'Values', $filter_array ) ) { |
| 58 | + $f->allowed_values = $filter_array['Values']; |
64 | 59 | } else { |
65 | 60 | $f->allowed_values = array(); |
66 | 61 | } |
Index: trunk/extensions/SemanticDrilldown/includes/SD_PageSchemas.php |
— | — | @@ -7,20 +7,20 @@ |
8 | 8 | * @author Ankit Garg |
9 | 9 | */ |
10 | 10 | |
11 | | -class SDPageSchemas { |
| 11 | +class SDPageSchemas extends PSExtensionHandler { |
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Returns an object containing information on a filter, based on XML |
15 | 15 | * from the Page Schemas extension. |
16 | 16 | */ |
17 | | - public static function createPageSchemasObject( $objectName, $xmlForField, &$object ) { |
| 17 | + public static function createPageSchemasObject( $tagName, $xml ) { |
18 | 18 | $sd_array = array(); |
19 | | - if ( $objectName != "semanticdrilldown_Filter" ) { |
20 | | - return true; |
| 19 | + if ( $tagName != "semanticdrilldown_Filter" ) { |
| 20 | + return null; |
21 | 21 | } |
22 | 22 | |
23 | | - foreach ( $xmlForField->children() as $tag => $child ) { |
24 | | - if ( $tag == $objectName ) { |
| 23 | + foreach ( $xml->children() as $tag => $child ) { |
| 24 | + if ( $tag == $tagName ) { |
25 | 25 | foreach ( $child->children() as $prop => $value) { |
26 | 26 | if( $prop == "Values" ){ |
27 | 27 | $l_values = array(); |
— | — | @@ -32,63 +32,61 @@ |
33 | 33 | $sd_array[$prop] = (string)$value; |
34 | 34 | } |
35 | 35 | } |
36 | | - $object['sd'] = $sd_array; |
37 | | - return true; |
| 36 | + return $sd_array; |
38 | 37 | } |
39 | 38 | } |
40 | | - return true; |
| 39 | + return null; |
41 | 40 | } |
42 | 41 | |
| 42 | + public static function getDisplayColor() { |
| 43 | + return '#FDD'; |
| 44 | + } |
| 45 | + |
| 46 | + public static function getFieldDisplayString() { |
| 47 | + return 'Filter'; |
| 48 | + } |
| 49 | + |
43 | 50 | /** |
44 | 51 | * Returns the HTML for setting the filter options, for the |
45 | 52 | * Semantic Drilldown section in Page Schemas' "edit schema" page |
46 | 53 | */ |
47 | | - public static function getFieldHTML( $field, &$text_extensions ){ |
| 54 | + public static function getFieldEditingHTML( $field ){ |
48 | 55 | //$require_filter_label = wfMsg( 'sd_createfilter_requirefilter' ); |
49 | 56 | |
50 | 57 | $filter_array = array(); |
51 | 58 | $hasExistingValues = false; |
52 | 59 | if ( !is_null( $field ) ) { |
53 | | - $sd_array = $field->getObject('semanticdrilldown_Filter'); |
54 | | - if ( array_key_exists( 'sd', $sd_array ) ) { |
55 | | - $filter_array = $sd_array['sd']; |
| 60 | + $filter_array = $field->getObject( 'semanticdrilldown_Filter' ); |
| 61 | + if ( !is_null( $filter_array ) ) { |
56 | 62 | $hasExistingValues = true; |
57 | 63 | } |
58 | 64 | } |
59 | 65 | |
60 | | - if ( array_key_exists( 'Name', $filter_array ) ) { |
61 | | - $filterName = $filter_array['Name']; |
62 | | - } else { |
63 | | - $filterName = ''; |
64 | | - } |
| 66 | + $filterName = PageSchemas::getValueFromObject( $filter_array, 'Name' ); |
| 67 | + $selectedCategory = PageSchemas::getValueFromObject( $filter_array, 'ValuesFromCategory' ); |
65 | 68 | $fromCategoryAttrs = array(); |
66 | | - if ( array_key_exists( 'ValuesFromCategory', $filter_array ) ) { |
67 | | - $selectedCategory = $filter_array['ValuesFromCategory']; |
| 69 | + if ( !is_null( $selectedCategory ) ) { |
68 | 70 | $fromCategoryAttrs['checked'] = true; |
69 | | - } else { |
70 | | - $selectedCategory = ''; |
71 | 71 | } |
72 | 72 | $dateRangesAttrs = array(); |
73 | 73 | $year_value = wfMsgForContent( 'sd_filter_year' ); |
74 | 74 | $yearOptionAttrs = array( 'value' => $year_value ); |
75 | 75 | $month_value = wfMsgForContent( 'sd_filter_month' ); |
76 | 76 | $monthOptionAttrs = array( 'value' => $month_value ); |
77 | | - if ( array_key_exists( 'TimePeriod', $filter_array ) ) { |
78 | | - $filterTimePeriod = $filter_array['TimePeriod']; |
| 77 | + $filterTimePeriod = PageSchemas::getValueFromObject( $filter_array, 'TimePeriod' ); |
| 78 | + if ( !is_null( $filterTimePeriod ) ) { |
79 | 79 | $dateRangesAttrs['checked'] = true; |
80 | 80 | if ( $filterTimePeriod == $year_value ) { |
81 | 81 | $yearOptionAttrs['selected'] = true; |
82 | 82 | } else { |
83 | 83 | $monthOptionAttrs['selected'] = true; |
84 | 84 | } |
85 | | - } else { |
86 | | - $filterTimePeriod = ''; |
87 | 85 | } |
88 | 86 | $manualSourceAttrs = array(); |
89 | 87 | $filterValuesAttrs = array( 'size' => 40 ); |
90 | | - if ( array_key_exists( 'Values', $filter_array ) ) { |
| 88 | + $values_array = PageSchemas::getValueFromObject( $filter_array, 'Values' ); |
| 89 | + if ( !is_null( $values_array ) ) { |
91 | 90 | $manualSourceAttrs['checked'] = true; |
92 | | - $values_array = $filter_array['Values']; |
93 | 91 | $filterValuesStr = implode( ', ', $values_array ); |
94 | 92 | } else { |
95 | 93 | $filterValuesStr = ''; |
— | — | @@ -108,11 +106,7 @@ |
109 | 107 | $valuesListAttrs = array( 'value' => '' ); |
110 | 108 | $comboBoxAttrs = array( 'value' => $combo_box_value ); |
111 | 109 | $dateRangeAttrs = array( 'value' => $date_range_value ); |
112 | | - if ( array_key_exists( 'InputType', $filter_array ) ) { |
113 | | - $input_type_val = $filter_array['InputType']; |
114 | | - } else { |
115 | | - $input_type_val = ''; |
116 | | - } |
| 110 | + $input_type_val = PageSchemas::getValueFromObject( $filter_array, 'InputType' ); |
117 | 111 | if ( $input_type_val == $combo_box_value ) { |
118 | 112 | $comboBoxAttrs['selected'] = true; |
119 | 113 | } elseif ( $input_type_val == $date_range_value ) { |
— | — | @@ -162,15 +156,15 @@ |
163 | 157 | $html_text .= Html::rawElement( 'select', array( 'name' => 'sd_input_type_num', 'id' => 'input_type_dropdown' ), $inputTypeOptionsHTML ) . "\n"; |
164 | 158 | $html_text .= "</p>\n"; |
165 | 159 | |
166 | | - $text_extensions['sd'] = array( 'Filter', '#FDD', $html_text, $hasExistingValues ); |
167 | | - |
168 | | - return true; |
| 160 | + return array( $html_text, $hasExistingValues ); |
169 | 161 | } |
170 | 162 | |
171 | | - public static function getFieldXML( $request, &$xmlArray ) { |
| 163 | + public static function createFieldXMLFromForm() { |
| 164 | + global $wgRequest; |
| 165 | + |
172 | 166 | $fieldNum = -1; |
173 | 167 | $xmlPerField = array(); |
174 | | - foreach ( $request->getValues() as $var => $val ) { |
| 168 | + foreach ( $wgRequest->getValues() as $var => $val ) { |
175 | 169 | if ( substr( $var, 0, 15 ) == 'sd_filter_name_' ) { |
176 | 170 | $xml = '<semanticdrilldown_Filter>'; |
177 | 171 | $fieldNum = substr( $var, 15 ); |
— | — | @@ -179,11 +173,11 @@ |
180 | 174 | } |
181 | 175 | } elseif ( substr( $var, 0, 17 ) == 'sd_values_source_') { |
182 | 176 | if ( $val == 'category' ) { |
183 | | - $xml .= '<ValuesFromCategory>' . $request->getText('sd_category_name_' . $fieldNum) . '</ValuesFromCategory>'; |
| 177 | + $xml .= '<ValuesFromCategory>' . $wgRequest->getText('sd_category_name_' . $fieldNum) . '</ValuesFromCategory>'; |
184 | 178 | } elseif ( $val == 'dates' ) { |
185 | | - $xml .= '<TimePeriod>' . $request->getText('sd_time_period_' . $fieldNum) . '</TimePeriod>'; |
| 179 | + $xml .= '<TimePeriod>' . $wgRequest->getText('sd_time_period_' . $fieldNum) . '</TimePeriod>'; |
186 | 180 | } elseif ( $val == 'manual' ) { |
187 | | - $filter_manual_values_str = $request->getText('sd_filter_values_' . $fieldNum); |
| 181 | + $filter_manual_values_str = $wgRequest->getText('sd_filter_values_' . $fieldNum); |
188 | 182 | // replace the comma substitution character that has no chance of |
189 | 183 | // being included in the values list - namely, the ASCII beep |
190 | 184 | $listSeparator = ','; |
— | — | @@ -206,15 +200,14 @@ |
207 | 201 | } |
208 | 202 | } |
209 | 203 | |
210 | | - $xmlArray['sd'] = $xmlPerField; |
211 | | - return true; |
| 204 | + return $xmlPerField; |
212 | 205 | } |
213 | 206 | |
214 | 207 | /** |
215 | 208 | * Displays the information about the filter (if any exists) |
216 | 209 | * for one field in the Page Schemas XML. |
217 | 210 | */ |
218 | | - public static function getFilterDisplayInfo( $field_xml, &$text_object ) { |
| 211 | + public static function getFieldDisplayValues( $field_xml ) { |
219 | 212 | foreach ( $field_xml->children() as $tag => $child ) { |
220 | 213 | if ( $tag == "semanticdrilldown_Filter" ) { |
221 | 214 | $filterName = $child->attributes()->name; |
— | — | @@ -231,9 +224,9 @@ |
232 | 225 | $values[$prop] = $value; |
233 | 226 | } |
234 | 227 | } |
235 | | - $text_object['sd'] = array( 'Filter', $filterName, '#FEE', $values ); |
| 228 | + return array( $filterName, $values ); |
236 | 229 | } |
237 | 230 | } |
238 | | - return true; |
| 231 | + return null; |
239 | 232 | } |
240 | 233 | } |
Index: trunk/extensions/SemanticDrilldown/SemanticDrilldown.php |
— | — | @@ -65,11 +65,12 @@ |
66 | 66 | $wgHooks['MagicWordwgVariableIDs'][] = 'SDUtils::addMagicWordVariableIDs'; |
67 | 67 | $wgHooks['LanguageGetMagic'][] = 'SDUtils::addMagicWordLanguage'; |
68 | 68 | $wgHooks['ParserBeforeTidy'][] = 'SDUtils::handleShowAndHide'; |
69 | | -$wgHooks['PageSchemasGetFieldDisplayInfo'][] = 'SDPageSchemas::getFilterDisplayInfo'; |
70 | | -$wgHooks['PageSchemasGetObject'][] = 'SDPageSchemas::createPageSchemasObject'; |
71 | | -$wgHooks['PageSchemasGetFieldHTML'][] = 'SDPageSchemas::getFieldHTML'; |
72 | | -$wgHooks['PageSchemasGetFieldXML'][] = 'SDPageSchemas::getFieldXML'; |
73 | 69 | |
| 70 | +// Register class with the Page Schemas extension |
| 71 | +if ( isset( $wgPageSchemasHandlerClasses ) ) { |
| 72 | + $wgPageSchemasHandlerClasses[] = 'SDPageSchemas'; |
| 73 | +} |
| 74 | + |
74 | 75 | $wgPageProps['hidefromdrilldown'] = 'Whether or not the page is set as HIDEFROMDRILLDOWN'; |
75 | 76 | $wgPageProps['showindrilldown'] = 'Whether or not the page is set as SHOWINDRILLDOWN'; |
76 | 77 | |