r100011 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100010‎ | r100011 | r100012 >
Date:01:34, 17 October 2011
Author:yaron
Status:deferred
Tags:
Comment:
Modified to reflect changes in Page Schemas v0.3
Modified paths:
  • /trunk/extensions/SemanticDrilldown/SemanticDrilldown.php (modified) (history)
  • /trunk/extensions/SemanticDrilldown/includes/SD_Filter.php (modified) (history)
  • /trunk/extensions/SemanticDrilldown/includes/SD_PageSchemas.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticDrilldown/includes/SD_Filter.php
@@ -24,42 +24,37 @@
2525 $template_all = $psSchemaObj->getTemplates();
2626 foreach ( $template_all as $template ) {
2727 $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 ) {
2929 $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 ) ) {
3732 continue;
3833 }
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'];
4236 } else {
4337 $f->name = $fieldObj->getName();
4438 }
 39+ $prop_array = $fieldObj->getObject('semanticmediawiki_Property');
4540 $f->property = $prop_array['name'];
4641 $f->escaped_property = str_replace( array( ' ', "'" ), array( '_', "\'" ), $f->property );
4742 $f->is_relation = true;
4843 if ( array_key_exists( 'Type', $prop_array ) && $prop_array['Type'] != 'Page' ) {
4944 $f->is_relation = false;
5045 }
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'];
5348 }
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'];
5651 $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'];
5954 $f->allowed_values = array();
6055 } elseif ( $f->is_boolean ) {
6156 $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'];
6459 } else {
6560 $f->allowed_values = array();
6661 }
Index: trunk/extensions/SemanticDrilldown/includes/SD_PageSchemas.php
@@ -7,20 +7,20 @@
88 * @author Ankit Garg
99 */
1010
11 -class SDPageSchemas {
 11+class SDPageSchemas extends PSExtensionHandler {
1212
1313 /**
1414 * Returns an object containing information on a filter, based on XML
1515 * from the Page Schemas extension.
1616 */
17 - public static function createPageSchemasObject( $objectName, $xmlForField, &$object ) {
 17+ public static function createPageSchemasObject( $tagName, $xml ) {
1818 $sd_array = array();
19 - if ( $objectName != "semanticdrilldown_Filter" ) {
20 - return true;
 19+ if ( $tagName != "semanticdrilldown_Filter" ) {
 20+ return null;
2121 }
2222
23 - foreach ( $xmlForField->children() as $tag => $child ) {
24 - if ( $tag == $objectName ) {
 23+ foreach ( $xml->children() as $tag => $child ) {
 24+ if ( $tag == $tagName ) {
2525 foreach ( $child->children() as $prop => $value) {
2626 if( $prop == "Values" ){
2727 $l_values = array();
@@ -32,63 +32,61 @@
3333 $sd_array[$prop] = (string)$value;
3434 }
3535 }
36 - $object['sd'] = $sd_array;
37 - return true;
 36+ return $sd_array;
3837 }
3938 }
40 - return true;
 39+ return null;
4140 }
4241
 42+ public static function getDisplayColor() {
 43+ return '#FDD';
 44+ }
 45+
 46+ public static function getFieldDisplayString() {
 47+ return 'Filter';
 48+ }
 49+
4350 /**
4451 * Returns the HTML for setting the filter options, for the
4552 * Semantic Drilldown section in Page Schemas' "edit schema" page
4653 */
47 - public static function getFieldHTML( $field, &$text_extensions ){
 54+ public static function getFieldEditingHTML( $field ){
4855 //$require_filter_label = wfMsg( 'sd_createfilter_requirefilter' );
4956
5057 $filter_array = array();
5158 $hasExistingValues = false;
5259 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 ) ) {
5662 $hasExistingValues = true;
5763 }
5864 }
5965
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' );
6568 $fromCategoryAttrs = array();
66 - if ( array_key_exists( 'ValuesFromCategory', $filter_array ) ) {
67 - $selectedCategory = $filter_array['ValuesFromCategory'];
 69+ if ( !is_null( $selectedCategory ) ) {
6870 $fromCategoryAttrs['checked'] = true;
69 - } else {
70 - $selectedCategory = '';
7171 }
7272 $dateRangesAttrs = array();
7373 $year_value = wfMsgForContent( 'sd_filter_year' );
7474 $yearOptionAttrs = array( 'value' => $year_value );
7575 $month_value = wfMsgForContent( 'sd_filter_month' );
7676 $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 ) ) {
7979 $dateRangesAttrs['checked'] = true;
8080 if ( $filterTimePeriod == $year_value ) {
8181 $yearOptionAttrs['selected'] = true;
8282 } else {
8383 $monthOptionAttrs['selected'] = true;
8484 }
85 - } else {
86 - $filterTimePeriod = '';
8785 }
8886 $manualSourceAttrs = array();
8987 $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 ) ) {
9190 $manualSourceAttrs['checked'] = true;
92 - $values_array = $filter_array['Values'];
9391 $filterValuesStr = implode( ', ', $values_array );
9492 } else {
9593 $filterValuesStr = '';
@@ -108,11 +106,7 @@
109107 $valuesListAttrs = array( 'value' => '' );
110108 $comboBoxAttrs = array( 'value' => $combo_box_value );
111109 $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' );
117111 if ( $input_type_val == $combo_box_value ) {
118112 $comboBoxAttrs['selected'] = true;
119113 } elseif ( $input_type_val == $date_range_value ) {
@@ -162,15 +156,15 @@
163157 $html_text .= Html::rawElement( 'select', array( 'name' => 'sd_input_type_num', 'id' => 'input_type_dropdown' ), $inputTypeOptionsHTML ) . "\n";
164158 $html_text .= "</p>\n";
165159
166 - $text_extensions['sd'] = array( 'Filter', '#FDD', $html_text, $hasExistingValues );
167 -
168 - return true;
 160+ return array( $html_text, $hasExistingValues );
169161 }
170162
171 - public static function getFieldXML( $request, &$xmlArray ) {
 163+ public static function createFieldXMLFromForm() {
 164+ global $wgRequest;
 165+
172166 $fieldNum = -1;
173167 $xmlPerField = array();
174 - foreach ( $request->getValues() as $var => $val ) {
 168+ foreach ( $wgRequest->getValues() as $var => $val ) {
175169 if ( substr( $var, 0, 15 ) == 'sd_filter_name_' ) {
176170 $xml = '<semanticdrilldown_Filter>';
177171 $fieldNum = substr( $var, 15 );
@@ -179,11 +173,11 @@
180174 }
181175 } elseif ( substr( $var, 0, 17 ) == 'sd_values_source_') {
182176 if ( $val == 'category' ) {
183 - $xml .= '<ValuesFromCategory>' . $request->getText('sd_category_name_' . $fieldNum) . '</ValuesFromCategory>';
 177+ $xml .= '<ValuesFromCategory>' . $wgRequest->getText('sd_category_name_' . $fieldNum) . '</ValuesFromCategory>';
184178 } elseif ( $val == 'dates' ) {
185 - $xml .= '<TimePeriod>' . $request->getText('sd_time_period_' . $fieldNum) . '</TimePeriod>';
 179+ $xml .= '<TimePeriod>' . $wgRequest->getText('sd_time_period_' . $fieldNum) . '</TimePeriod>';
186180 } 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);
188182 // replace the comma substitution character that has no chance of
189183 // being included in the values list - namely, the ASCII beep
190184 $listSeparator = ',';
@@ -206,15 +200,14 @@
207201 }
208202 }
209203
210 - $xmlArray['sd'] = $xmlPerField;
211 - return true;
 204+ return $xmlPerField;
212205 }
213206
214207 /**
215208 * Displays the information about the filter (if any exists)
216209 * for one field in the Page Schemas XML.
217210 */
218 - public static function getFilterDisplayInfo( $field_xml, &$text_object ) {
 211+ public static function getFieldDisplayValues( $field_xml ) {
219212 foreach ( $field_xml->children() as $tag => $child ) {
220213 if ( $tag == "semanticdrilldown_Filter" ) {
221214 $filterName = $child->attributes()->name;
@@ -231,9 +224,9 @@
232225 $values[$prop] = $value;
233226 }
234227 }
235 - $text_object['sd'] = array( 'Filter', $filterName, '#FEE', $values );
 228+ return array( $filterName, $values );
236229 }
237230 }
238 - return true;
 231+ return null;
239232 }
240233 }
Index: trunk/extensions/SemanticDrilldown/SemanticDrilldown.php
@@ -65,11 +65,12 @@
6666 $wgHooks['MagicWordwgVariableIDs'][] = 'SDUtils::addMagicWordVariableIDs';
6767 $wgHooks['LanguageGetMagic'][] = 'SDUtils::addMagicWordLanguage';
6868 $wgHooks['ParserBeforeTidy'][] = 'SDUtils::handleShowAndHide';
69 -$wgHooks['PageSchemasGetFieldDisplayInfo'][] = 'SDPageSchemas::getFilterDisplayInfo';
70 -$wgHooks['PageSchemasGetObject'][] = 'SDPageSchemas::createPageSchemasObject';
71 -$wgHooks['PageSchemasGetFieldHTML'][] = 'SDPageSchemas::getFieldHTML';
72 -$wgHooks['PageSchemasGetFieldXML'][] = 'SDPageSchemas::getFieldXML';
7369
 70+// Register class with the Page Schemas extension
 71+if ( isset( $wgPageSchemasHandlerClasses ) ) {
 72+ $wgPageSchemasHandlerClasses[] = 'SDPageSchemas';
 73+}
 74+
7475 $wgPageProps['hidefromdrilldown'] = 'Whether or not the page is set as HIDEFROMDRILLDOWN';
7576 $wgPageProps['showindrilldown'] = 'Whether or not the page is set as SHOWINDRILLDOWN';
7677